Basic JavaScript - Assigning the Value of One Variable to Another

I am utterly flummoxed, confused and frustrated. The original link in my opinion is unhelpful, vague and nebulous. I have tried a myriad of different things in order to assign the contents of a to b however, no matter what I tried for the past two hours it is not working. I realise that my code is probably missing something and that this is my fault completely. I just would like someone to walk me through this.

Your code so far

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

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

Your browser information:

User Agent is: Mozilla/5.0 (X11; CrOS x86_64 14541.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36

Challenge: Basic JavaScript - Assigning the Value of One Variable to Another

Link to the challenge:

b was already declared - you should not declare it again

You shouldn’t declare this variable either

This line is close, but what if a was a different value? This line needs to work no matter what value is stored in a

hello and welcome to fcc forum :slight_smile:

  • this is not correct, you should get error in console, for multiple reasons

lets read from instructions

The above declares a myVar variable with no value, then assigns it the value 5 . Next, a variable named myNum is declared with no value. Then, the contents of myVar (which is 5 ) is assigned to the variable myNum . Now, myNum also has the value of 5

var myVar;
myVar = 5;
var myNum;
myNum = myVar;
  • do you understand whats happening in this example? if so then simply “replace” and adjust variable names and values

happy learning :slight_smile:

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