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 trialbrendon hanson
6,191 Pointscode isn't working
var students = [
{
name: 'Brian',
Acheivements: 4,
Points: 257,
Track: 'IOS'
},
{ name: 'Linda',
Acheivements: 7,
Points: 399,
Track: 'Android'
},
{
name: 'Chester',
Acheivements: 5,
Points: 150,
Track: 'JS'
},
{
name: 'Felisha',
Acheivements: 9,
Points: 990,
Track: 'Python'
},
{
name: 'Luke',
Acheivements: 1,
Points: 780,
Track: 'Ruby'
}
];
var message = ' ';
var student;
var question;
//Custom Function that replaces document.write with a better alternative function print(message) { var outputDiv = document.getElementById('output'); outputDiv.innerHTML = message; } // These are the student reports function getReport( student ) { var report = '<h2> Student: ' + student.name + '</h2>'; report += '<p> Track: ' + student.Track + '</p>'; report += '<p> Acheivements: ' + student.Acheivements + '</p>'; report += '<p> Points: ' + student.Points + '</p>'; return report; }
while (true) {
question = prompt("Would you like to see our student records? Type in any name to find their record or type Quit to exit");
if (question === null || question.toLowerCase() === 'quit') { break;
} for (var i = 0; i < students.length; i += 1) { student = students[i]; if ( student.name === question ) {
message = getReport( student );
print(message);
}
} }
print(message);
Joseph Wasden
20,407 PointsTough to say. How should the code be working? What do you expect it to do? what is it doing instead? Are you working with a data set of some kind? Consider including some data mock up, if so. Also, consider including the accompanying HTML, and consider reformatting the code in question. As it stands, it is difficult to read.
I can only say it looks like you are missing a closing }, but I'm not sure if that just got lost in the cut/paste or not. Good luck!
1 Answer
Steven Parker
231,275 PointsAs explained in the Teacher's Notes, the browser will not render any output until the loop ends (you type "quit" or click on "cancel"). If you were expecting to see output as you typed that might be the issue.
Otherwise, please explain in more detail.
Also, when posting code, use the instructions for code formatting in the Markdown Cheatsheet pop-up below the "Add an Answer" area. Or watch this video on code formatting.
brendon hanson
6,191 PointsI fixed it up a bit and I know about the browser thing this is a different issue...can you see any problems?
Steven Parker
231,275 PointsPlease describe the issue you are experiencing.
brendon hanson
6,191 PointsThe prompt pops up but when I input something and close it there's nothing same for when I type quit it closes but there is nothing. It should show all of the reports when I type quit. Also when I type in someones name it should show their individual profile when i close the prompt
Steven Parker
231,275 PointsIt works for me. I enter a name (note that it must be an exact match, including upper and lower case) and then type "quit" (or click "cancel") and I see the record on the page.
I did have to add this bit of HTML to the page first:
<div id="output"></div>
brendon hanson
6,191 PointsI feel really STUPID! I didn't type in exact match! I wasted 6 hours on trying to figure out what was wrong. Thanks!
Steven Parker
231,275 PointsDon't feel bad, mistakes are the best teachers.
If you want, you could make it case-insensitive like this:
if (student.name.toLowerCase() === question.toLowerCase()) {
Anyway, glad to help. Happy coding!
brendon hanson
6,191 Pointsbrendon hanson
6,191 PointsIgnore the variables on top