Binary Branching explainer

The aim of this puzzle: Use if statements to control which block of code runs.

Walkthrough of the solution: An if statement tests is used to run a block of code only if a certain condition is true. It looks like this:

if (this is true) {
  do this;
}

In this puzzle, the value variable uses the pickRandom() function to choose between 1 and 0. The 1st if statement tests if value === 0. If this is true, print('zero') runs. If value is not 0, then print('zero') will not run.

To complete the puzzle, add a 2nd if statement like the first, but test if value === 1. Inside the code block {}, add print('one').

Sample code solution:
(Tap below to reveal)

var value = pickRandom([0, 1]);
print(value);

if (value === 0) {
    print('zero');
}

if (value === 1) {
    print('one');
}


JavaScript Concepts: Binary Expression (===), Calling Functions, Conditionals (if statement), Data Structures (Arrays), Identifiers, Variable Declaration
Grasshopper Concepts: pickRandom(), print()

1 Like

I am sure that NLP languages ​​are very nervous, I am starting to feel bored and never give up :fist::muscle::v:

2 Likes

Don’t be ashamed to fail to succeed u must fall. The Code is everywhere and is everything never give up learn hard and everything will be possible.:robot:

What am I doing wrong?

Hi @Clyde_Daka you are doing a nested condition, but you need to do one condition below the other one.

1 Like

Hey put it down in the 1 st statement not inside

Hpor this helps