Plus and Minus explainer


#1

The aim of this puzzle: To add to and subtract from the variable z
Walkthrough of the solution: This puzzle demonstrates how the plus (+) and minus (-) operators can be used to update a variables value. In the initial code the number 0 is being added to z, and then subtracted from z. To solve this puzzle, change 0 to be a number 1 or greater.
Sample code solution:
(Tap below to reveal)

var z = 5;
z = z + 5;
print('z is ' + z);
z = z - 3;
print('z is now ' + z);

JavaScript Concepts: Binary Expression (=, +, -), Calling Functions, Identifiers, Variable Declaration
Grasshopper Concepts: print()


#3

This makes no sense to me


#4

To solve the puzzle, there are 2 things you need to change:

  1. Edit the 1st number 0 into a larger number, like 5
  2. Edit the 2nd number 0 into a larger number, like 3

That will turn your code into the solution code:

var z = 5;
z = z + 5;
print('z is ' + z);
z = z - 3;
print('z is now ' + z);

I’ll explain what each line does.

var z = 5;
“Create a variable (a thing to store data) called z and store the number 5 in it.”

z = z + 5;
“Change the value of z into z + 5. Since z was storing 5, this becomes 10.”

print('z is ' + z);
"Output the text 'z is 10' since the value of z is now 10"

z = z - 3;
“Change the value of z into z - 3. Since z was storing 10, this becomes 7.”

print('z is now ' + z);
"Output the text 'z is 7' since the value of z is now 7"

–Frankie


#5

I have tried to enter the code as per your instructions in the exercise, but I am now convinced that the code is ironically incorrectly coded, thus making it impossible to solve. How do I complete the exercise when it is incorrectly coded and impossible to solve?


#6

Can you post a screenshot of your code?

–Frankie