Storing Values with the Assignment Operator3

Tell us what’s happening:

Your code so far

// Setup
var a;
var b = 2;

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

Your browser information:

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

Link to the challenge:


Not awesome
b is already declared, you don’t need to declare it again with var.
var a = var b is a syntax error, you can’t use var in the value you are assigning to a variable.
Also, the challenge is asking you to assign the content of a to the variable b, remember you assign what is to the right of the assignment operator = to the variable to the left of it.

assume that ‘is’ is equal to ‘=’ operator
var a is an empty container
var b is a container containing 2
// Only change code below this line

a and b is already containers and no need to make them container using var
put something into container just like in b
put the container ‘a’ into container ‘b’

1 Like

a = 7;
var b;
var b = var a
it’s getting me aggravated

So there are two separate things going on here:

  1. variables are being declared;
  2. variables are being assigned a value.

the declaring part of the process is pretty simple:

var a;

is all that is required to declare a variable. That’s it. Once declared, it exists, doesn’t need to be re-declared.

Now the second part is where that variable is assigned a value. That can look like this:

a = 7;

That assigns the integer 7 into my variable a (or it initializes a with the value of 7). The two CAN be combined, but only the first time - once a variable has been declared, remember, it doesn’t need to be done again. So we can combine them like this:

var a = 7;

This sets aside the variable’s space (declares the variable), and assigns it a value (initializes the variable). We can do that with both a and b, works fine.

Later on, however, you are being told to assign the value of b into a. It’s an assignment, and a has already been declared (the variable name already exists). So how do we assign a value? Look above, where I set it to 7. We can set it to anything, even the value of another array:

var foo = "one";
var bar = "two"

// later on, I want to set foo to the value of bar:
foo = bar; // <-- I didn't use var or anything, as they both already exist!