JavaScript JavaScript Loops, Arrays and Objects Tracking Multiple Items with Arrays Useful Array Methods

Uche Onuekwusi
Uche Onuekwusi
12,375 Points

Please Help me,

The condition that prints to to the page telling the user that that the player type is available is not working. Please review my code below

var fullSquad = [ "Pogba", "Lukaku", "Sanchez", "Martial" , "Matic" ];

var search;

while(true) { search = prompt("Search for your favorite Manchester united player. Type List to see the list of all the players available or type quit to exit "); search = search.toLowerCase();
if (search === "quit" ) { break;

} else if (search ==="list") { alert(fullSquad.join(",")); } else { if (fullSquad.indexOf(search) > -1) { document.write("yes" + search + "is available for selection");

}else {

alert( search + " is not on the team"); }
}

}

1 Answer

Kieran Barker
Kieran Barker
14,971 Points

Hey, Uche! It looks like you had a few syntax errors. I've played with your code a bit and come up with this:

https://w.trhou.se/4j63xirr6l

Let me know if any of it doesn't make sense! It's not necessarily the best solution, but it works OK.

Kieran Barker
Kieran Barker
14,971 Points

No problem. You can mark this question as solved by choosing a best answer. Happy coding ?