If Editor 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) {

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 color variable uses pickRandom to choose between the colors blue and green. The variable is then printed to the console, so we can see which color was picked.

The if statement checks if color is equal to blue. If this is true, then a blue box should be drawn.

Sample code solution:

var color = pickRandom([blue, green]);

if (color === blue) {

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

why print(color) after the variable declaration is there?
I don’t understand

I got it now.
I thought this code was not running

1 Like