Ive entered every variance

I’m meant to assign the value of Var a to Var B. I’ve tried it a number of different ways. been stuck here for 25 minutes and I just dont understand I guess.
Ive tried:

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

What am I doing wrong?

// Setup

var a;

a = 7;

var b;

// Only change code below this line

var a = var b;

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

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

Your browser information:

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

Challenge: Assigning the Value of One Variable to Another

Link to the challenge:

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

You are sprinkling var in a lot of weird places. I’d start by resetting the challenge.

You can’t use a and b before you declare them.
You can’t declare a variable on the right of an assignment operator.

1 Like

Those are all the different, separate ways ive tried entering it.
each line is a separate entry that was denied.

It entered weird when I copy and pasted.

I can’t understand your post. What is your current code? What parts do and don’t you understand?

If you combine all of your solutions together, I don’t have any way of guessing where one solution attempt ends and the other begins.

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

// Only change code below this line

^^This is the orginal code without anything added.

Ok. What’s your most recent attempt?

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

That code declares the variable a, assigns the value 7 to a, and then declares the variable b with no value. Is that what you intended to do?

the question instructs me to assign Var A’s value too Var B.

so I tried doing so which I’d have thought would be: Var a = var b;
That didn’t work.
I tried a = b; That also didnt work.
I tried b = 7; this also didnt work.

In the most recent code you shared, you didn’t assign any value to b. You left it undefined.

That assigns the value of b (if b was correctly declared) to the variable a.

That assigns the value 7 to b and doesn’t have anything to do with a.

1 Like

Redeclaration is bad. Never do that.

Also, you can’t put var on the right side of the =

This puts b’s value into a

Your code has to work no matter what value is stored in a

Also, please please please use the formatting.

hm… you know in something like php, that’s close to how you would write it… but this is JavaScript, so let’s go around asking ourselfs, what is “var”?
Well “var” is a word that tells JavaScript that the following thing will be a variable and it should tell the memory to make some room for it and also remember the name. That’s it. Once done, JavaScript knows this is a variable.
It’s like preparing a chair and a nametag - once it’s prepared, you can give it to whatever value you want to hold it.

Next up is “=” and what does that do? It tells JavaScript to store whatever value is ON THE RIGHT into the variable on the left.

So if I want to get a “name” variable with “Tom”, I write var name = "Tom".
Now read the task and example again and try to understand what is happening there.

1 Like

Unless theres also a lesson on freecodecamp regarding formatting I don’t really know what your talking about. I’m a novice. Don’t have money to take college courses or a bootcamp. Which is why I’m here. I apologize though. I struggle with bits and pieces of this. Theres a lot of rules to the code that arent readily included in the lessons.
I finally figured it out although now I’m not sure of Formating and dont want to post more code that will irritate people.

This is the freeCodeCamp lesson on how to declare a variable.

This is the freeCodeCamp lesson about how to assign a value to a variable.

This is the formatting we’ve been talking about.

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