Lab JS5: if-else Statements and Programmatic Movement



IMPORTANT: Upload your programatic animations (Part 5) to Canvas as .wick files.
Upload the written answers to Parts 1-3. Do not upload Part 4.

Part 1: Logical Operators

For the questions below, assume that p, q, and r are boolean expressions with the values true, true, and false, respectively. Find the value of each boolean expression.
  1. p && !q
  2. p && q || !r
  3. p && ! (q || r)
  4. !p && q
  5. p || q && r




Part 2: Relational Operators !, < ,>, <= ,>= , === , !==



Assume the following variables have been declared:

  let   m  = -5;
  let   n   = 8 ;
  let   x  = -3;
  let   y  = 0.0;
  let   z  = 4;


For the questions below, find the value of the boolean expressions.

  1. m <= n
  2. -2 * m <= 8
  3. x <= y && y <=z
  4. ! (x < y)
  5. 0 <= m <=10
  6. 0 <= m && m <=10




Part 3: Practice Writing Boolean Expressions

For the questions below, assume that p, q, and r are boolean expressions with the values true, true, and false, respectively. Find the value of each boolean expression.
  1. Write a boolean expression to express that x is nonzero.
  2. Write a boolean expression to express that x is strictly between -10 and 10.
  3. Write a boolean expression to express that both x and y are positive or both x and y are negative.
  4. Re-write the code segment below as efficiently as possible.
    			if (x < y && x === 0)
    				console.log("Red");
    			if (x < y && x !== 0)
    				console.log("White");
    			if (x >= y)
    				console.log("Blue");
    		




Part 4: Program Animation

  1. Construct a Ball Clip object.
  2. Program the Ball to move horizontally in a fixed velocity.
  3. When the Ball hits the left wall, it should shrink in size in size, bounce off the wall, and move toward the right wall.
  4. When the Ball hits the right wall, it should expand in size in size, bounce off the wall, and move toward the left wall.







Part 5: Create the game of Pong

  1. Construct a Ball Clip object.
  2. Construct a Paddle Clip object.
  3. Program the Padd to move vertically as the user moves their mouse/cursor.
  4. Program the Ball to move horizontally and vertically in a fixed velocity.
  5. The ball should bounce off the top, bottom, and right wall during collision.
  6. When the Ball misses the paddle, it should disappear from the screen.