More Number Operators Explainer


The aim of this puzzle: Update the test (the part inside the parentheses) of the second if statement to check if x is greater than 5 OR if y is greater than 5.
Walkthrough of the solution: There are several new concepts in this puzzle!

The first new concept is the introduction of two new comparison operators, < (less than) and > (greater than). They are used to compare two different numbers.

The second new concept is the “or” logical operator ||. “Or” is similar to the “and” operator &&, and is used to check if 2 separate conditions are true. However, only 1 condition needs to be true for the || operator to return true. For example:

if (time > 10 || tiredness === 'yes') {
  print('You should go to bed');

The if statement uses || to check if time is greater than 10 and if tiredness is equal to 'yes'. Because this is using the || operator and not &&, only one of these conditions needs to be true.

To complete the puzzle, use the || operator to make the 2nd if statement check if x > 5 OR if y > 5.

Example solution:
(Tap below to reveal)

print('x is ' + x);
print('y is ' + y);
if (x > 2 && y < 7) {
    print('x is greater than 2, and y is less than 7');
if (x > 5 || y > 5) {
    print('x or y, or both, are greater than 5');

JavaScript Concepts: Logical Operators, Comparison Operators, If Statement, Calling Functions, Identifiers
Grasshopper Concepts: print()

Additional Code (hidden code that runs before the puzzle’s code):

var x = pickRandom(13);
var y = pickRandom(13);

This code uses pickRandom to choose a number between 0 and 13.

unlisted #2

listed #3