NodeSchool workshopper:js ex 14 Looping through arrays

I seem to be having some trouble grasping looping through arrays.

Here is a link to my remix.!/glossy-jumper

If I comment out “(pets[i] = pets[i] + ‘s’);” it will console.log the original array, but with the code left in I am receiving “undefineds”. It is adding the s to “undefined”, so it seems like my “i” is undefined, but I believe I have it defined.

Any help would be appreciated. Super new to this stuff.


Hey Jon!

You have a couple of syntax issues:

You don’t need the ; after defining the for loop but before {, so it should just be: for ( var i = 0; i < length; i++) {
Then inside the for loop, your contents does not need to be in braces. So it should be pets[i] = pets[i] + 's';

1 Like