Cant Assign "a" with "b"

Tell us what’s happening:
Describe your issue in detail here.

Your code so far


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

Your browser information:

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

Challenge: Assigning the Value of One Variable to Another

Link to the challenge:

i cant assign a with b

a = 7 so instead of writing b = 7 you have to use the a variable in the assignment … so b = a will works and that what they mean by assign a to b in the exercise

remove this lines

Hey @bluryboss
You are doing it the reverse way around.
b should have the value of 7, but you should not do b = 7;
Instead, notice how a already has been assigned the value 7 and use this to give b the same value.

Currently, you are assigning “a” the value of “b”. It wants you to assign “b” the value of “a” :slight_smile:
I hope this makes sense?

they also said to assign b with 7

the instructions on the left:

You should not change code above the specified comment.
b should have a value of 7.
a should be assigned to b with =.

those are what the challenge will be testing for when you click “Run the tests”…

By assigning a to b , b will have a value of 7 and will pass the tests on the left. That is the point the lesson is trying to illustrate to you.

also, something to know is…

If you assign a to b , and change the value of a later, the value of b will not change.

var a;
a = 7;
console.log("a is " + a)

var b;
b = a;
console.log("b is " + b)

a = 3;

console.log("a is " + a)
console.log("b is " + b)

Output:

a is 7
b is 7
a is 3
b is 7 // still 7

If you assign a to b, and change the value of b later, the value of a will not change.

var a;
a = 7;
console.log("a is " + a)
var b;
b = a;
console.log("b is " + b)
b = 3;

console.log("a is " + a)
console.log("b is " + b)

Output:
a is 7
b is 7
a is 7 // still 7
b is 3

The order of assignment and where things are assigned in the code makes a difference. Seems simple, but is an important concept to understand.

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