Operators Worksheet

Question 1

What are the comparison operators used for?

Comparison operators are symbols used to compare two values. They help us decide if something is true or false. Here are the main ones:
Equal to (==) Checks if two things are the same (e.g., 5 == 5 is true).
Strictly Equal (===) Checks if two things are exactly the same in value and type (e.g., 5 === '5' is false because one is a number and the other is a string).
Not Equal to (!=) Checks if two things are different (e.g., 5 != 3 is true).
Greater than (>) Checks if one number is bigger than the other (e.g., 7 > 3 is true).
Less than (<) Checks if one number is smaller than the other (e.g., 3 < 7 is true).
Greater than or equal to (>=) Checks if one number is bigger or the same as the other (e.g., 5 >= 5 is true).
Less than or equal to (<=) Checks if one number is smaller or the same as the other (e.g., 4 <= 6 is true).
These are used in code to make decisions, like checking if a player has enough points to win or if a number is within a certain range.

Question 2

Explain the difference between the logical AND operator (&&) and the logical OR operator (||).

The logical AND (&&) and logical OR (||) operators are used to combine conditions in programming. Here's the difference between them:
Logical AND (&&)
Both conditions must be true for the result to be true. If either one (or both) is false, the result is false.

Logical OR (||)
Only one condition needs to be true for the result to be true. If both conditions are false, the result is false

Question 3

Which operator would you use to find the remainder from dividing 2 numbers.

To find the remainder from dividing two numbers, you would use the modulus operator (%).

Question 4

Which operator would you use if you wanted to find out if two values were NOT equal?

To check if two values are NOT equal, you would use the not equal operator (!=) or the strict not equal operator (!==).

Coding Problems - See the 'script' tag below this h3 tag. You will have to write some JavaScript code in it.

Always test your work! Check the console log to make sure there are no errors.