Thank you. I fixed it.
Modifier Math explainer
Hi, I understand what it’s looking for and completed the exercise, I just don’t fully understand why if x=5 and you’re updating that to a new value of x=x+5 why it’s not 5=5+5. Why does the second x in the equation retain the last value for x, but the first one doesn’t?
Hi @Murcielago,
The important thing to keep in mind is that in JavaScript, =
does not mean what it means in mathematics. In JavaScript and many other programming languages, it indicates that the calculated value of the expression on the right is assigned to the variable on the left.
Thus, in x=x+5
, x+5
evaluates to 5+5
, which evaluates to 10
, which is then assigned to the variable on the left, which is x
.
Does that help? I think maybe the tutorial needs to explain more thoroughly that the various symbols do not have quite the same meaning as in mathematics.
–Scott.
Hey @Murcielago,
In addition to what @Scott_McNay has explained, it may be useful to walk through each element as if we are talking to the computer. So let’s break it down:
x =
: this part is telling the computer that we want to assign a new value to x
. Whenever you see the =
symbol it means that the variable (or identifier) on the left is going to be assigned a new value.
x + 1
: this is on the right side of the assignment symbol, meaning it is the new value that will be given to x
. At this point, x
still has it’s old value. The computer will look ‘up’ to see what x
has been holding to date, and then add 1 to it.
Hopefully this helps!
H
I put in your solution exactly and I still get errors from your app that I can’t complete this puzzle
Are you still stuck on this puzzle? Make sure you’re using num
for numbers and str
for words. If there are quote marks around a number, then it will be seen as a keyboard character, not an amount.
You can also upload a picture of your code here to get another look.
–Frankie
Hrmm… It is confusing how the language always appears to be mathematical but is actually a combination of directive shorthand and math. Instinctively I look at it and think “x” does not equal “x + 5”… (How is it not a circular reference? Is “x =” of “x = x + 5” happening independently of “x + 5”? Wouldn’t it make more sense to write “x + 5 = x” if the goal is to update the value of x? How does the print function portion know to show the value of x rather than displaying “x”?)
Will be interesting to see how complex math functions are handled later on (if those are in the program). Thanks for your explanation.
EDIT: I see you guys answered my questions above. Sorry, disregard my post
Hi @Sportyyyy,
print x
will always only ever print the contents of the variable named x
.
print "x"
will always only ever print the literal string shown within the quotes: “x
”.
The difference is that one has quotes and the other doesn’t.
Each language has it’s own rules. In most modern languages, you can use this:
a = b = 2
to determine if b
equals 2
and assign true
or false
to a
.
But, I recall seeing code for what I think was an old mainframe version of BASIC in which the value of 2
would be assigned to the variable b
, then the value of the variable b
(which was now 2) would then be assigned to the variable a
.
As a clarification to future readers:
In JavaScript and most languages a single equal sign =
is the assignment operator. That means “make one side equal to the other side” (usually, change the left side to match the right side).
In JavaScript and many other languages, multiple equal signs, ==
or ===
, is the equality operator. That means “check if one side is already equal to the other side”.
That means a = b = 2
will be interpreted as “set b
to 2, and then set a
to the value of b
which is 2”. Which makes a
and b
have a value of 2. The code a = b === 2
can be rewritten as a = (b === 2)
, and you can break it up into two parts:

b === 2
, “Is the variableb
storing the value 2?”. That is eithertrue
orfalse
. a = (either true or false depending on if b was equal to 2)
@Sportyyyy
Here is a chart that lists the order that each operator is executed. If you remember the order of operations and PEMDAS from arithmetic, this is the same thing except with more operators included. You’ll notice that assignment =
is one of the last operations to happen. That means you’ll usually have all the math compress down to a simpler form and that final value will be assigned to the variable. There’s also a column called “Associativity” which shows the order if there are multiple operators with the same precedence/ranking. In JavaScript and nearly all languages, assignment evaluates the right side and assigns that value to the left side.
–Frankie
Flip a Coin explainer
The code you’ve added is fine. The feedback is still looking at the original starter code and asking you to change the numbers from 0 to something else.
If you remove the starter code (the first 5 lines) and keep the code you added, you should pass the puzzle.
–Frankie
Hi @CoreyW07,
It looks you haven’t changed the 0
from x = x  0
yet. It’s just above the last print statement. You should be able to move on if you change it.
Hope this helps
Basically I have the same example equation. It looks like this:
var x=5;
X= x + 0;
Print (‘x is’ + x);
X= x  0;
Print (‘x is now’ + x);
What do I do?
It looks like you have the starter code. In that case, you only need to make 2 changes: turn each 0 into a different number.
If that doesn’t work, try resetting the puzzle using the button, and then try editing the zeros.
–Frankie
The print()
at the bottom should be using the x
variable instead of the number 7.
Try changing the 7
to x
, and be sure to use the variable name x
and not a string 'x'
.
–Frankie
Mine is broke i dis the answer this says to use but grasshopper itself says incorrect format