Ask coding questions

← Back to all posts
I need help!!
HannahWyse (1)

my code is not working... I cant fix it. Can someone show me how to do it

InvisibleOne (2683)

The issue is in your for loop, for each product you are checking if it is in your list of products, and if it isn't, you break the loop, the issue is that you are breaking the loop the first time! so unless the item the user wants is the first item in your list the for loop cannot find it. A better way is to do this:

var n = fruits.includes(products);
if (n) {
  console.log("Yes we do have that product")
} else {
  console.log("Now we don't have that product")