Storing Values with the Assignment Operator - Assigning a to b with =

Tell us what’s happening:

Instructions (the first three are correct and the last one I can’t seem to get):
Do not change code above the line
a should have a value of 7
b should have a value of 7
a should be assigned to b with =

Link to the challenge:

This is what I have so far:

// Setup
var a;
var b = 2;

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

I tried assigning a to b like:
var b = var a;

but this did not work. What am I doing wrong?

Whenever you are using the word var, you are telling the program ‘hey, here is a completely new variable I have not declared before’. So you only need to declare variables once with the var keyword and the following times just use the variable name, in this case a.

I’ve edited your post for readability. When you enter a code block into the forum, precede it with a line of three backticks and follow it with a line of three backticks to make easier to read. See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.


You…are awesome. I was wondering what I was doing wrong.

Okay so, I understand var is used to declare a variable, so putting

var b = var a; 

will not work. But does this mean i just put

b = a;

cause when I did that it still did not work. Maybe I am just not understanding. :expressionless:

b= a is fine, but before that you need to give a value to the a variable. The exercise asks you for 7 I think.
The relation is basically A equals 7 and B equals A. So B will equal 7.

1 Like

So I just tried it, I guess because the code was still all white, I thought I was doing something wrong. But the following worked. Thank you so much!