For loop into a for loop😕


#1

WHAT AM I DOING WRONG ! I NEED HELP ANSWERING THIS QUESTION
'inside of the existing for loop's block, write another for loop that loops over friendPlaces. This time, instead of using the i as the variable name, use j, so we don't overwrite any variables.''

myPlaces = ['Mall','Disney','iceskating']
var friendPlaces = ['Movies','Mall','Rollerskating']
for (var i = 0;i < myPlaces.length; i++) (for(var j = 0; < friendPlaces.length; i++) { console.log(myPlaces[i])};


#2

Scrunched up code is not only hard to read, it is also hard to debug. Give your code some breathing room and all the closing braces their own line. We can spot one error, right off the bat, the paren before the second for should be an opening brace.

for (var i = 0; i < myPlaces.length; i++) {           // correct brace
    for (var j = 0; j < friendPlaces.length; j++) {   // correct for iterator
        console.log(myPlaces[i]);                     // added semi-colon
    }                                                 // added misssing brace
}                                                     // removed semi-colon

The logging may not be asked for, but for debugging it's okay. Comment out when you add the rest of the code.


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.