Headlights explainer


Aim of the puzzle: Use the “does not equal” operator !== in an if statement to check if headlights need to be turned on.
Walk through of solution: The !== equality operator is used to check the if 2 values are not equal to each other.

In this puzzle, the timeOfDay variable uses pickRandom() to choose between the strings 'day' and 'night'. The variable is then printed to the console so we can see which value was chosen when the code runs.

The starter code has an example if statement that uses the !== equality operator to check if timeOfDay is not 'night'. If this is true, then the code in its code block runs, and the string 'lights off' is printed to the console.

To solve the puzzle, add a 2nd if statement that uses !== to check if timeOfDay is not 'day'. Inside the code block, use print() to print the string 'lights on'.

When the code runs, timeOfDay will randomly choose between 'day' and 'night'. If it is not 'night', then the 1st statement will run. If it is not 'day', then the 2nd if statement will run.
Sample code solution:

var timeOfDay = pickRandom(['day', 'night']);

if (timeOfDay !== 'night') {
    print('lights off');

if (timeOfDay !== 'day') {
    print('lights on');

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

listed #2