How to get the first part of this basic loop exercise right?

Nice job since you're just starting.

You almost got it. Just declare the variable as an empty string.

// this is the line that needs to be changed
var hash = '';

for(....) {
  hash += "#";
  console.log(hash);
}

This way as you add to the "hash" variable inside the loop, it doesn't have that extra "#" from variable declaration.


Your code is being executed 'top to bottom'.

In your 'for loop' the first iteration adds an # to the already declared var hash and that makes it ## and this gets 'logged' by the console.

All you need to do is put the console.log(hash) before the hash = hash + "#".

console.log(hash);
hash = hash + "#";

This will make sure that in the first iteration, first of all a '#' will be 'logged' and only then hash = hash + "#" will get to work :)

Tags:

Javascript