-2

if(rightPressed && paddleX < canvas.width-paddleWidth) {
    paddleX += 7;
}
else if(leftPressed && paddleX > 0) {
    paddleX -= 7;
}

&&, <

Doesn't the first operator end with true or false? How do you calculate it with the inequality sign?

  • The way operator precedence works - or, just speaking it out loud: "If rightPressed, or if paddleX is smaller than some other value". Similar to PEMDAS that you learned in school, except with a few more operators. – CertainPerformance May 07 '22 at 00:50
  • i.e., it's evaluated as `rightPressed && (paddleX < (canvas.width - paddleWidth))` – Slaw May 07 '22 at 01:24

0 Answers0