Hat Trick explainer

The aim of this puzzle: Use the “does not equal” operator !== in an if statement to give hints in a guessing game.

Walkthrough of the solution: The !== equality operator is used to check the if 2 values are not equal to each other.

In this puzzle, the ball variable uses pickRandom() to choose between the numbers 1, 2, and 3. As this is a guessing game, these numbers represent which hat the ball is hiding under.

The starter code has an if statement that uses !== to check if ball is not equal to 1. If this is true, the code inside the if statement’s code block will print the message 'Not under hat 1'.

The 2nd if statement checks if ball is not equal to 3. Inside the code block, use print() to print a string, such as 'Not under hat 3' to the console.

Sample code solution:
(Tap below to reveal)

var ball = pickRandom([1,2,3]);
if (ball !== 1) {
    print('Not under hat 1');
if (ball !== 3) {
    print('Not under hat 3');

JavaScript Concepts: Code Block (if statement), Calling Functions, Identifiers, Variable Declaration
Grasshopper Concepts: pickRandom(), print()