# Simpler Math explainer

#1

Aim of the puzzle: Use the `++` and `--` operators to change the value of a variable.

Walk through of solution: On the first line, the `x` variable is defined with the value 5. The next line increments (adds 1 to) the `x` variable. You can see the results printed by the next line.

Now, tap on the `x` on the next line all by itself. Tap the `--` button to decrement (subtract 1 from) the `x` variable. When you run the code now you will see that the value of `x` went back down by 1.

Sample code solution:
(Tap below to reveal)

``````let x = 5;
x++;
print('x is ' + x);
x--;
print('x is now ' + x);
``````

Javascript Concepts: Variables (`let`), Increment (`++`), Decrement (`--`)

Grasshopper Concepts: `print()`

#4

I cannot add to a string inside a bracket . When I type âx is nowâ I cannot add + x between the end of the string and the bracket.
Hope I have explained my problem so that it can be understood!

#5

OK, no need to reply. I fixed it by not doing this by myself, rather just reverting to the original and adding one operator, which I see now was the intention.

#6

Hi,

I donât understand from where is coming that string âx isâ and âx is nowâ.

Probably because of that, that we changed the value of x. But Iâm not sure how to use itâŚ

Iâm looking forward for your help.
Thank u!
Nina

#7

Btw. I just realized as well, that is a âletâ, so what about print in {} if is âletâ not a var?

Help, i stuck, totally
I mean, that exercise i finished correct, but i donât understand it really.
Thank u!

#8

The strings `'x is'` and `'x is now'` are not special. We could have used `'The value of the variable is '` and `'After updating x, it has a value of '`, or any other string. Those strings are being combined with value of `x` using the `+` symbol. When you use `+` with a string and a variable, it will try to convert the variable into a string and then combine them to create a single string. In this puzzle, the strings donât actually change the value of the `x` variable; theyâre just used to help us know what the number being printed out is representing.

âFrankie

#9

With this puzzle, a `let` and `var` would behave the same way because there are no separate code blocks `{}` as you mentioned. If you use `let` in your code, it doesnât mean that you need to add curly brackets `{}`; it only means that if there is a code block, then the `let` canât leave it. If a `let` variable is created and itâs not inside of any curly brackets, then there is no boundary on where that variable can be used, except that you canât use it before youâve created it.

In this example code, Iâve written `'yes'` where the `x` can be used, and `'no'` where it cannot be used:

``````'no'
{ //Beginning of the let's code block
'no, not created yet'
let x = 0;
'yes, same block'
{
'yes, still inside the bigger block'
}
'yes'
} // End of the let's code block
'no'
{
'no'
}
'no'
``````

âFrankie