Storing Values with the Assignment Operator Help! A should be assigned to B

Tell us what’s happening:
Help! A should be assigned to B

Your code so far


// Setup
var a;
var b = 2;
var a = 7;
var b = 7;

// Only change code below this line

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:61.0) Gecko/20100101 Firefox/61.0.

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

so the first thing you had to do was assign 7 to a, which you did perfectly by writing:

a = 7;

Now, they want you to assign a to b. So, just do the exact same thing you did but with a and b.
(that is, if I said, assign 20 to b, then you would write b = 20 right? So a to b is no different than 20 to b. Exactly the same but instead of 20 , use a).

2 Likes

Like: var b = a;
Thanks brain raked a bit an i’m just starting.

1 Like

In the example it was written

myNum = myVar;

So I thought it is enough if I write a=b; since they are both variables. But nope, it does not work. var a=var b; also does not work. Example was wrong! :slight_smile:

What’s your current code? If you use the Ask for help button you can create a post with your code and we will be able to see it and help you (or copy your post here formatting it with the backticks! In the post editor you can use the </> button)

Anyway, it is correct that you can assign the value of b to a using a = b
var a = var b is a syntax error. var is the keyword to declare a variable, it can’t be used in the part that is going to be assigned

Also they want you to assign a to b, not b to a

I misunderstood the task but now I understand. Thanks, I really tried to assign a to be when a is 7. My bad.

I also have a problem with this topic

var a;
var b = 2;

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

I ran the test but it says " a should be assigned to b with ="
not quite sure what I have done wrong

You didn't close your values.

// Setup

var a;

var b = 2


// Only change code below this line

a = 7;

b = a ;

The closing tag ";" is very important in your code. 

1 Like