Lock Box Explainer


#1

The aim of this puzzle: Use the “and” logical operator && inside the if statement to check if 2 separate conditions are both true.
Walkthrough of the solution: The && logical operator is used to check if 2 separate conditions are true. It returns true only if both conditions are true. For example:

if (day === 'weekday' && holiday === 'no') {
  print('You have to go to work today');
}

The if statement checks to see if day is equal to 'weekday' AND if vacation is equal to 'no'. The string 'You have to go to work today' will be printed only if both conditions are true. If 1 or both conditions are false, then the code in the if statement’s code block will not run.

In this puzzle, the code variable has the value 451, and the key variable has the value 'yes'.

To complete the puzzle, update the if statement to use the && operator to check if key === 'yes' AND code === 451.
Sample code solution:
(Tap below to reveal)

var code = 451;
var key = 'yes';

if (key === 'yes' && code === 451) {
    print('Unlock successful.');
}

JavaScript Concepts: Logical Operators (&&), Assignments, Calling Functions, Array Expression
Grasshopper Concepts: print()


listed #2