Assigning var a to var b

Tell us what’s happening:

I am trying to assign a to b but nothing seems to be happening. Have I done this incorrectly?

Your code so far


// Setup
var a;
var b = 2;

// Only change code below this line
var a=7;
var 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/68.0.3440.106 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/storing-values-with-the-assignment-operator

You redeclare var a and b triple times

I have changed it to this:

// Setup
var a;
var b = 2;

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

Still the same issue.

Task:
a should be assigned to b with =
a should have the value of 7
b should have the value of 7

The declarations mean you say to comp: hey this text ‘a’ is var, one time and than the comp know that a is variable not a text.
https://www.w3schools.com/js/js_variables.asp

1 Like

Thanks for the clarification it worked :grinning:

I like I help, and click on solution [] on my answer

1 Like

This is the answer:

var a=7;
var b=7;
var b = a;

Your code may be passing but it’s not actually how it should be done.

var a=7;
var b=7;
var b = a;
  1. Why are you redeclaring the variables?
  2. Why are you assigning 7 to the b variable?

We would also prefer you not directly post answers, but only helpful comments and guidance.

1 Like

Thank you for the review, i am new here and i will improve my post content.
I tried many times before not assigning 7 to b, but didn’t work out, tough I was wrong.

No problem, and welcome to the community.

This is all you should need, I change things a bit to make it different from the answer.

// Setup
var someVariable;
var someOtherVariable = 'some value';

// Only change code below this line
someVariable = 'some other value';
someOtherVariable = someVariable;
2 Likes

Thank you for the example.
I appreciate this, I cleared some doubts I had before.