Basic JavaScript - Assigning the Value of One Variable to Another

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

Your code so far
i can not figurout the correct code

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


// Only change code below this line

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36

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

Link to the challenge:

i donot understant why i am doing this things this is not useful for any project what i mean i will not use this in my page i wish if java funny like css

CSS only makes a website look pretty. JavaScript is required for any interactive functionality.

You will need javascript to make things fun for sure!
Here’s a fun example to help you stay motivated (there are many more…)

but how did you do that it is cool but maybe i cannot do that becuase i donot understatend that

that’s what I mean though. It is cool because of javascript.
So I hope this motivates you to learn that language.

It looks like you are at the very start of your JavaScript journey and it’s a hard road but it’s by far the most fun I’ve had since learning HTML CSS or JS.

JavaScript is a lot of thinking and problem solving but there is nothing more satisfying than finally getting something to work!! It’s what can

would you like to teach me java

I am learning javascript too, so I can help you a little bit when you run into problems here on the forum. The example I showed you was not created by me. It is just something I wanted to show you so you can see there is value in learning to program it.

but i donot understant the code what i know is java give the instrucations for the page what instrucations i don’t know and what is the instruactions should i know

i will be greatful if you do thar please

The course here on freecodecamp is structured to teach you starting from the very beginning. I like to use the courses on here and just research things I don’t fully understand. If I personally get stuck and don’t understand something very well, I’ll stop what I’m doing and try to research/watch videos until I understand it a little better.

JavaScript is really tricky at first and it’s almost like learning math! Everything you learn will be very confusing at first, but it will all begin to click and slowly make sense. Just keep at it :slight_smile:

Java is not the same thing as JavaScript.

Let me try to explain this a different way for you.

The computer has a memory. The memory is for remembering data.
An example of data that the computer can remember is numbers.

Now try to imagine the memory of the computer like drawers.
Each drawer can hold one thing.
To keep track of which drawer has what, the drawers have names. We can these names “variables”. So a variable is actually the name of part of the computer’s memory.

When someone wants the computer to remember something in its memory, they use a language like javascript to tell it to do that.

In this case the language requires that we use a certain ‘vocabulary’ and ‘grammar’. The vocabulary of a language is things like ‘var’ which is a special key that is understood to mean ‘variable’.
The grammer of the language is what we refer to as syntax.
Syntax tells us the order we write things in so they make sense to the computer.

So if I said:

var a;

It will know that I want to store something in memory and that I want to call that area of memory ‘a’.

But if I write

a var;

That is the wrong syntax and it will not understand it the way I want it to.

so then:
var a;
a = 7;

What these two are doing is that they are telling the computer to store a number 7 inside a variable called ‘a’.
We “declared” the variable first. This is an important step. To ‘declare’ is like an announcement. We are announcing to the computer that we want to store something in memory (in a variable called a)

Then we did an “assignment”.
a = 7;

This has to be written a very specific way. The syntax (or grammar) of the language javascript is what is telling us to do it like that.

a = 7;

this will store the number 7 in memory in a location called a

So always the variable on the left hand-side of the equal is the memory location we are storing things in. (so try to remember that if it is on the left, it is the location we are keeping things in - in memory)…

var b;

this one declares another place in memory (which is at the moment not having anything interesting in it - yet).

We want to tell the computer to copy the contents of the memory location we call a and put it inside of b.

Remember the rules.
The variable on the left is the location of memory where things will be placed (or another way to say this, the variable on the left is getting assigned something).

So how would you tell the computer to take the content of a and put it inside of b?

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