Wanderlust Step 41 Help Needed

I’m on step 41 on the Wanderlust project in JavaScript. It was suggested to replace the .forEach() with a WHILE statement but I am utterly confused…help? I’m trying to get more than four venues and make sure none of them are repeated.

https://www.codecademy.com/courses/introduction-to-javascript/projects/wanderlust

1 Like

If you return say 10 venues, and still want to only display 4, but want to choose 4 unique venues at random, you could use while in this manner:

const randomIndexes = [] //empty array to hold 4 random numbers

while randomIndexes.length < 4 {
  //logic to produce 4 random numbers between 0 and 9 (10 possibilities)
  //you could also just write the code to choose 4 venues here instead of the index numbers to use
  //just remember to check that they are unique
  //you wouldn't want the computer to randomly choose the same venue 4 times
  randomIndexes.push(value) // value would be your random number or random venue
}  
return randomIndexes; // or randomVenues

That might be the body of a function or method to generate the random index numbers. Hope this at least gives you an idea of where to start. I’d be happy to help further if you need it. Happy Coding!

3 Likes