// Initialize these three variables
var a;
5= a;
a= 5;
var b;
b= 10;
var c;
c= I am a;
// Do not change code below this line
a = a + 1;
b = b + 5;
c = c + " String!";
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:65.0) Gecko/20100101 Firefox/65.0.
Oh my…
Alright. So, when you declare a variable with var or let, you are not required to assign it an initial (get it? initial–initialized?) value:
var a;
let b;
But this can be dangerous. Well, not super dangerous in JavaScript since they default to undefined, but in some other languages they could be some random value.
Usually, it is good practice to, when you are declaring a variable, give it an initial value, or initialize it. You assign a value to a variable with a single equals sign: = and the variable always goes on the left and the value going into said variable always goes on the right:
let foo = "bar";
assigns the string “bar” to the variable name foo.
The way I do:
check what the task ask you: a should be defined and evaluated to have the value of 6
and we have instructions:
// Do not change code below this line
a = a + 1;
so quick math
a=6; a= 5+1;
so at the beginning we should have a=5; var value can change down the line
you need to add variable values, because at the moment they are empty
You might want to go back to the start again and re-read the assignments, don’t rush it.
5 = a;
The left-hand side of the assignment operator is the receiver, you are trying to assign a variable to a primitive data type. You can not assign a value to 5, it is what it is, the number 5 and nothing else.
c = I am a;
The text on the right-hand side here is supposed to be a string, you use quotes "" or '' around text to make it a string “I am a”
This is declaring variables
var a;
var b;
var c;
This is initializing the variables
a = "some string";
b = 42;
c = b;
This is declaring and initializing the variables in one line.