Help! Basic JavaScript: Assigning the Value of One Variable to Another

Tell us what’s happening:

I keep getting an error message when running the tests, no matter what I try I can’t pass a=b. I try using var a = var b with different spacing, and just using a =b. The other tests have passed to get b =7. I tried switching browsers as well. I’m stuck. Please help. The initial post for getting help is useless in my opinion. Unless we are supposed to combine the variables for the name it has nothing to do with this challenge.

Your code so far


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

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





Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.146 Safari/537.36.

Challenge: Assigning the Value of One Variable to Another

Link to the challenge:

Task is to assign a variable to another variable. Here, both a and b are already declared and you declared them again in the same scope.

It should be like this: a = b;

I have tried that. It keeps giving me an error. I even cut and paste your response.

You’re asked to assign a to b, so it should be b = a;.

I made assumption based on your code. That’s why I wrote a = b;

Please read the task description carefully.

1 Like

Thank you! That fixed the problem, but the breakdown of the tests makes it sound like a = b.
You should not change code above the specified comment.

Passed

b should have a value of 7.

Passed

a should be assigned to b with = .

1 Like

Test description sounds perfect to me. "a should be assigned to b".

but the solution is b = a. It sounds backwards to me. This isn’t the first time I have run into the test result not matching the exact answer
Thanks for your help!

1 Like

The test and the written description match. The sentence

Assign the contents of a to variable b .

means to take what’s inside a and put it inside of b. The variable on the left side of the = is the variable that is having it’s contents reassigned.

I get what you mean by it sounding backwards. In JavaScript, = does not mean “is equal to.” Instead, you could say “has an assignment of.”

A variable is a storage container. You can picture a box in your head. You put things inside the box by assigning them. In this lesson, we have a = 7. That means that the box labelled a has a 7 inside it.

So when they tell you to “Assign the contents of a to variable b ,” another way to phrase that is “place ‘a’ inside ‘b.’” Now b will have a inside it, and a = 7, so now if you console.log b, the result will be 7.
Hope that helps.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.