Assigning variables

Tell us what’s happening:
Error message:

a should be assigned to b with =.

Your code so far

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

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

Your browser information:

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

Challenge: Assigning the Value of One Variable to Another

Link to the challenge:

I’ll give you a hint. You should only add one line of code. You already have the variables a and b declared and a has the value of 7. You just want to put the value in a in b. But don’t use the number 7 in your answer. You can only use the variables.

it should be
b = a ;
as value is assigned to b .

Please don’t give answers here. We try to help people find the answers for themselves.

Just curious as to why a = b; doesn’t work. Seems the same to me.

The variable on the left hand side of the equals sign gets the value on the right hand side of equals sign. So a = b says “put the value of b in a”. But b doesn’t have a value (it’s technically undefined). What you want is “put the value of a in b”. So b needs to be on the left hand side of the equals sign.

1 Like

here ‘b’ is the container and it will get the value of ‘a’ as its content .
eg :- if a has some value b will get that value ;
it is kinda same when we use ‘==’(equal to operator)

This isn’t really true. The single equals sign is for assignment. The double equals sign is checking equality. Two different things.

will keep that in my mind for next time .(BTW it is my 1st reply so. I was waiting for a solution to my problem.)

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