Error in Printing Array with While Loop


#1



https://www.codecademy.com/en/courses/javascript-beginner-en-ASGIv/2/4?curriculum_id=506324b3a7dffd00020bf661


I'm receiving an error in this code. It's telling me "expected ']'." I know exactly where the problem is as well - it works fine unless the part surrounded by asterisks, on the line right below the start of the while loop, is included. Any suggestions?


for (i = 0; i < 5; i++) {
    console.log("I know a song that'll get on your nerves.");
};
var wouldjaShyaddap = 0;
var shutup = ["Hey", "kid", "wouldja", "shyaddap?"];
while(wouldjaShyaddap < 4) {
    console.log(shutup[0:**wouldjaShyaddap**]);
    wouldjaShyaddap++;
    console.log("I know a song that'll get on your nerves.");
};
var awwMan = false;
do {
    console.log("Aww, man!");
} while(awwMan);


#2

this line:

console.log(shutup[0:**wouldjaShyaddap**]);

why? You can simple do: shutup[wouldjaShyaddap], to access the items in the arrays.


#3

Oh. Oops. Thanks :smile: Would the other way have worked? For example, had I needed to go from index 1 to the value of wouldjaShyaddap, what's the correct syntax for that?


#4

wouldjaShyaddap is a number which changes in the loop, so you can access all items in the array, apart from that i don't understand your question