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

Why is the value in the prompt not being utilized to obtain results?

I apologize in advance for posting my code like this, cant find the option to post the code so it is easier to read.

 var message = "";
var student; 
var search

function print (message){
  var outputDiv = document.getElementById('output');
  outputDiv.innerHTML = message;
}



function getStudentReport( student ){  
var report = '<h2> Student:' + student.name + '</h2>'; 
    report += '<p> Track:' + student.track +   '</p>';
    report += '<p> Achievements:' + student.achievments +'</p>';
    report += '<p> Points:' + student.points +   '</p>';
    return report;
}

while (true){
  search = prompt('search student records')
  search = search.toLowerCase();
    if (search === null || search === 'quit'){
      break;
    }
   for(var i = 0; i < students.length; i++){
    student = students[i];
     if( student.name === search){
        message = getStudentReport(student);
        print(message);
     }

}} ```

Sorry for not having an answer to your actual question, but wanted to let you know how to use code in comments; at the bottom of the text box you should see "Reference this Markdown Cheatsheet for syntax examples for formatting your post.".

Click on Markdown Cheatsheet and copy & paste the example for html, change the syntax type for whichever you need and paste your code.

When looking at your code, it looks like you're missing a ; at the end of your prompt method.

1 Answer

Steven Parker
Steven Parker
243,318 Points

The code looks OK, though the lack of a couple of semicolons may not be "best practice".

But you didn't show what goes in the "students" array. If the student names are stored in mixed case, there will never be a match because the search term is always converted into lower case.

thanks for the tips on the semicolons, i will definitely be more aware of this. & I have checked the students array and everything is in lowercase. & it is still not using the value in the prompt method. Going to keep at this till i figure it out. thanks for the pointers Steven

Steven Parker
Steven Parker
243,318 Points

I made up some data and it worked. To facilitate analysis of your exact and complete code, make a snapshot of your workspace and post the link to it here.