Flag Chooser explainer

Aim of the puzzle: Edit an if statement.
Walk through of solution: If statements are used to run a block of code only if a certain condition is true. It looks like this:

if (x === 5) {
  print(x)
}

Inside the () is the test. It uses the equality operator === to check if x is equal to 5. If this is true, then the code inside the {} will run, and x will be printed to the console. If x is not 5, then the program will skip over the if statement, and the code inside the {} will not run.

In this puzzle, the flag variable uses pickRandom to choose between the strings 'France' and 'Gabon'. The 1st if statement checks if flag is equal to 'France'. If this is true, then the code drawBoxes('bwr bwr') will draw the French Flag.

A 2nd if statement has been set up to check if flag === 'Gabon'. To complete the puzzle, finish the drawBoxes function inside the {} by setting the argument to 'ggg yyy bbb'. If flag is equal to 'Gabon', then this code will draw the Gabonese flag.

Sample code solution:

var flag = pickRandom(['France', 'Gabon']);
print(flag);

if (flag === 'France') {
    drawBoxes('bwr bwr');
}

if (flag === 'Gabon') {
    drawBoxes('ggg yyy bbb');
}

Javascript Concepts: Variables, If Statements, Strings
Grasshopper Concepts: print(), drawBoxes(), pickRandom()

2 Likes