Storing Values with the Assignment Operator misunderstanding

Tell us what’s happening:

I do not understand how to complete this problem. Also why cant I put my code above line 5? This is kind of vague for newbies like me ii dont understand what i am doing wrong, i even tried watching the youtube video by Beau.

Your code so far


// Setup
var a;
var b = 2;

// Only change code below this line
var a = 7;
var b = var a;

Your browser information:

User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:60.0) Gecko/20100101 Firefox/60.0.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/storing-values-with-the-assignment-operator

When you declare a variable using the var command, that is kind of like labelling an empty box. You can not have two boxes with the same label as you have done.
To assign a value to a variable, just treat it like you would a math equation like y=3 would mean the variable y has the value 3.
So remove the extra vars and make sure you put the variable that is getting the value on the left if the equals . Values on right.

1 Like

Thank you for replying, but I am still a bit confused. How do I have 2 boxes with the same label? I understand y= 3, but shouldnt var b = var a; “Assign the contents of a to variable b” and shouldnt var a = 7; “Assign the value 7 to variable a”?

2 tasks:
1.Assign the value 7 to variable a
2. Assign the contents of a to variable b

Wow the first aswer made me go back to the last challenge, your right i was totally ignorant on what declaring a variable was thank you very very much! Now i get why the code must be written AFTER line 5 :D.
Now to read the rest of your answer…

-@ var a= 6: nice i didnt know i was doing 2 things there it looked like 1 just defining the variable thanks for clarifying what initializing a variable is.

-@ so look at your original code below: When I looked at the code before reading your last paragraph my code still semi made sense to me . Then i read the last paragraph and everything click like tetris. Thank you!!!

If var a; is called a “declaration”, does that mean b = a; is called a regular “operation”? Or what do we call these things(statements?) in javascript we are doing now. Like in html i write div tags, in css we write rulesets, what is this called in javascript?

Thanks a million times!