It won't even show an error on the console


#1

https://www.codecademy.com/courses/learn-javascript-loops/lessons/loops/exercises/for-loops-iii?action=lesson_resume&course_redirect=introduction-to-javascript


let myPlaces = [‘home’, ‘rome’, ‘The dome’]
let friendPlaces = [‘Home’, ‘Espana’, ‘chicago’]

for (let myPlacesIndex = 0; myPlacesIndex < myPlaces.length; myPlacesIndex++) {

for (let friendPlacesIndex = 0; friendPlacesIndex < friendPlaces.length; friendPlacesIndex++) {
if (myPlaces[myPlacesIndex] === friendPlaces[friendPlacesIndex]) {
console.log('Match: ’ + myPlaces[myPlacesIndex]);
}
}
}


Nothing is being logged to the console, and no error is appearing.


#2

This will also not print anything.

if (false) {
  console.log('hello')
}

If your code is supposed to print something, then you’ll need to review what events should lead up to that.
For example, in my piece of code here there’s a condition for executing the code that will print something, and it’ll need to be true, but is not, so if I change false to true I’ll get something to print. In your case you’ve got loops, you’d need to make sure that iterations happen, and you’ve got a condition, so you’d need to make sure that turns true during at least one iteration


#3

Or to be more direct, ‘home’ does not equal ‘Home’ so you aren’t ever getting a match, so it never prints. Change one to match the other, and it should work as expected.


#4

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