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 trialJesse Dispoto
Front End Web Development Techdegree Graduate 14,538 PointsCan't figure out where to put a loop in order to continuously prompt user...
let message = " ";
let html = " "
let answer;
answer = prompt("Search student records. Enter a name or type quit to exit the program.")
//for each index in array
for (let i = 0 ; i <students.length ; i++){
html+= "<ul>"
//for each property value within each object
for (let student in students[i]){
//if user answer equals the name property of individual object within loop
if (answer == students[i].name){
//displays name as heading
if (student == "name"){
html+= "<h3>" + student + ": " + students[i][student] + "</h3>"
}
//displays following characteristics in a list
else {
html+= "<li>" + student + ": " + students[i][student] + "</li>"
}
}
//if user answer is quit
else if (answer == "quit"){
break
}
}
html+= "</ul>"
}
document.write(html);
This is as far as I got regarding this challenge. I am having a really hard time trying to get this in a loop so the user is shown a prompt, even after you type the name, like in Dave's video. Right now, If you type a name, it displays the info on the page but then that's it. The user is not prompted to input another name or quit. And if you type quit OR anything else that is not a name, the program quits. When I try to put it in a while loop or do...while loop, it just creates an infinite loop or doesn't display the right info. Can someone help me out and suggest what I would need to do in order to continuously be display the prompt?
1 Answer
Steven Parker
231,236 PointsRight now, you have a loop to print the properties, but to prompt more than once you will need to enclose everything in another loop.
If you're having trouble with an outer loop never stopping, try sharing that code so we can give you a more specific answer.