Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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

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
15,028 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.

thanks a lot

Kieran Barker
Kieran Barker
15,028 Points

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