Super basic javascript ( like the 3rd challenge in)

Tell us what’s happening:
Describe your issue in detail here.

Your code so far


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

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

= b; 


/how the heck do you assign a and b??

it’s like 3:15 am here and I can’t figure out how to do this. PLEASE HELP!

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.2 Safari/605.1.15

Challenge: Assigning the Value of One Variable to Another

Link to the challenge:

Hi @jennybean007 !

Welcome to the forum!

I would reset the lesson.
Your answer only needs to be one line of code.

The challenge wants you to assign the contents of a to variable b .

Take a close look at this line of the example code again.

myNum = myVar;

You see how they are assigning myVar to myNum?

In your challenge, you need to do the exact same thing but assign a to b.

Remember, only one line of code.
Hope that helps!

2 Likes

Hey @jennybean007!

The fact is that a variable represents a location in your computer’s memory, when your program runs.

It might help in thinking of a variable as an open box you wrote a name on. The name on the box is the variable name or “label”.

You have 2 boxes here: box “a” and box “b”.

Rather than just values, since these are small numbers in your example, imagine you have a bunch of pennies.

var a = 7

You get the box labeled “a” on the outside and you fill it with 7 pennies.

Now you have another variable you declare:

var piggybank;

Piggybank in this case is an empty box, with the name “piggybank” written on it, but that is otherwise empty.

I say to you: “Make the contents of piggybank equal to the contents of ‘a’”

If you were doing this manually, you would probably find your box labeled “a”, and look inside of it, to find that it had 7 pennies in it.

You would then go to your source of pennies, and count out 7 and place them into the “piggybank” box.

This is an analogy to what you need to do here. The computer does all the work for you, of making the boxes and labelling them with your variable names, and duplicating values.

So all you really need is the syntax for making one javascript variable equal to another. In my example that would be:

piggybank = a;

This is a pet peeve of mine, but personally, I don’t like to encourage the use of ‘;’ in javascript when it is not needed. So if I wrote this javascript it would be:

var a = 7
var piggybank
piggybank = a
console.log(piggybank)

I hope that helps you conceptualize the relationship between variables and locations in memory, sometimes referred to as “addresses” or “references”.

One of the single most confusing things in javascript is the difference between the way simple variable types are handled and more complex types that are actually javascript objects.

Now might not be the best time to watch this, but when you are further along and more comfortable, it may help you avoid a lot of confusing and head scratching aspects to javascript that aren’t immediately intuitive.

1 Like

Tell us what’s happening:
Describe your issue in detail here.

Your code so far


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

// Only change code below this line
b = 7
a = 7;//the content of a is equal to the value of b

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.2 Safari/605.1.15

Challenge: Assigning the Value of One Variable to Another

Link to the challenge:

Hello there.

Do you have a question?

If so, please edit your post to include it in the Tell us what’s happening section.

Learning to describe problems is hard, but it is an important part of learning how to code.

Also, the more information you give us, the more likely we are to be able to help.


Your code should work even when you don’t know what number is stored in a.

Remember what I said about one line of code?

Also, you answer should not contain numbers in it.
Just the variable names of a and b

Reset the lesson and think about adding one line of code.

Also, take a look at the example again.

Hope that helps!

Thanks so much for your help! So… what would be the correct answer to the challenge?

I am not understanding. If

myNum = my Var ;

And my challenge is to assign a to b…
shouldn’t it be

7 = b;

since is b’s value is 7?

The way assignment works is that what is on the right hand side of the = sign gets assigned to the left hand variable.

For example, if I have a variable called myName and wanted to assign it to a variable called fccStaff then here is the code for that.

fccStaff = myName

The same logic applies to this

A quick clarification about your point here

Right now, a holds the value of 7.
The cool thing about variables is that you can just reference the variable name when you assign it to another.

Once you get the correct answer, then you can add a console.log at the end of your code then you will see that b will now hold the value of 7.

correct one line answer will go here
console.log(b)

Also, technically this code here

says you want to assign the variable b to the number 7 which is not what you want :grinning: