Javascript Unitialized variables

Tell us what’s happening:

Your code so far


// Initialize these three variables
  var a;
  var b;
  var c;

// Do not change code below this line

a = a + 1;
b = b + 5;
c = c  + " String!";

 a = 6;
 b = 15;
 c = "I am a String!";

You should not be changing or adding any code below that line.

1 Like

When a variable is declared, a space in memory is set aside for it. This would be something like:

var a;
var b;
var c;

That is a declaration. Initialization, on the other hand, means “setting an initial value to.” So in THAT case, you would do both: declare the variable, and give it a value:

var a = 3.14159;
var b = "The quick brown fox";
var c = "Foo Bar Baz";

Now, you have a detective problem. You are being given three FINAL values:

a should equal 6,
b should equal 15,
c should equal "I am a String!"

BUT!! There are some operations being performed on those variables: the three lines

a = a + 1;
b = b + 5;
c = c + " String!";

Those are operating on the values you have already (or should have already) initialized! That means you need to both declare them as variables with the var keyword, and set them to a starting value. What should the starting values be? Well, in the case of a, some value that, when one is added to it, equals six.