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 trialInês Lamares
2,079 PointsThe alert box only pops-up, if I introduce a name that doesn't exist the first time the prompt box appears, why?
Here is the code, hope some one can help me, thanks! https://w.trhou.se/48xgx9ug8s
1 Answer
Simon Coates
28,694 Pointsmaybe try resetting the student count each time through the loop. eg.
while(true){
search = prompt( "To search for a student record please insert the name or quit to exit." );
noStudent= 0;
Simon Coates
28,694 PointsSimon Coates
28,694 PointsI'm not very good at javascript, but you could replace the count with a boolean, count the matching records (print not found if matchingrecords === 0), or use students.length instead of 5. I would have tried something like:
nb: this also alters print, so that it appends to the div, rather than storing the complete message.
Inês Lamares
2,079 PointsInês Lamares
2,079 PointsHi Simon, Thanks so much! So obvious and I couldn't see it. Both work, but the 2nd option it's better. thanks again!