-4

Here's my script:

var alphabet = ["A", "B", "C", "D", "3", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"];
var str = [];

for (i=0; i<alphabet.length; i++) {
    str.push(i);
    console.log(str.join(""));
}

It's printing out the indices of str (0, 01, 012...) rather than the values (A, AB, ABC...). What is going on here?

pleiovn
  • 7
  • 3
  • 1
    `alphabet[i]` will give you what you need. You may want to [read this](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for) – PSL Sep 24 '16 at 00:48

1 Answers1

1

You have error in loop (push(i) instead of push(alphabet[i])). Correct loop:

for (i=0; i<alphabet.length; i++) {
    str.push(alphabet[i]);
    console.log(str.join(""));
}
jonzee
  • 1,600
  • 12
  • 20