Basic JavaScript - Assigning the Value of One Variable to Another

Tell us what’s happening: I’m having trouble assigning a to b. I also tried

Describe your issue in detail here.

Your code so far

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

// Only change code below this line

var b; // creating the variable b
b = 7; //the variable is equal to 7

var a; // creating the variable a 
a = b;

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36

Challenge Information:

Basic JavaScript - Assigning the Value of One Variable to Another

The answer to this challenge is a lot simpler than you might think.
Firstly, the variables a and b have already been declared (using var), so you shouldn’t redeclare them.
You can assign the value of one variable to another simply using = however (as shown in the challenge description). That is all you need to do. Just make sure you assign the variables the right way around.

2 Likes

Hello @leilihashemi

Assign the contents of a to variable b.


Look at "var a; " on line one. Here we declared the varaible a then on line two we assigned variable a the value of 7 “a = 7;” On the third line of code we declared the variable b “var b;”

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

// Only change code below this line

## Tests

* Waiting:You should not change code above the specified comment.

* Waiting:`b` should have a value of `7`.

* Waiting:`a` should be assigned to `b` with `=`.

Now below the line that says // Only change code below this line
assign var b the var a as the value using what we just went over declaring the a variable then assigning a var aiable the value of 7.

– Happy Coding!

2 Likes

Thank you for your reply! I realized my order was incorrect

2 Likes