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

Tammi Carter
Tammi Carter
5,360 Points

Please help? When attempting to search the students records only appear once I hit cancel , quit isn't working??

var message = '';
var student;
var search;

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

function getreports(students){

  var report = '<h2> Name: '+student.name + '</h2>';
  report += '<p>Track: ' + student.track + '</p>';
  report += '<p>Points: ' + student.points + '</p>';
  report += '<p>Achievements: ' + student.achievements + '</p>'; 
  return report;
}

  while (true) {

  message = '';
search = prompt('Enter a students name to search, once the search is complete type the word QUIT to close the prompt');
  if (search === null || search.toLowerCase() === 'Quit' ){
    break;
  }

    for (var i = 0; i < students.length; i += 1) {
  student = students[i];
  if (student.name.toLowerCase() === search.toLowerCase() ) {
    message += getreports(student);
  }
    }
    if(message === ''){
      message = 'No records found: '+search;
    }
    print(message);
  } 

4 Answers

Steven Parker
Steven Parker
229,732 Points

This code is converting the input into lower case, then comparing it to "Quit" (with capital "Q"), so it's not possible for it to match.

Compare the lower-cased input with "quit" (all lower case) instead.

Tammi Carter
Tammi Carter
5,360 Points

Thank you Steven!!! So why is it that I can’t get each students data to appear until after I hit cancel or clear? The Data appears for the last student name that I input and only appears after I quit or cancel

Steven Parker
Steven Parker
229,732 Points

In case you're not on the page with those notes, the behavior of modern browsers has changed since the video and now browsers don't render the page until the JavaScript code completely finishes.

Tammi Carter
Tammi Carter
5,360 Points

Thank you Jamie I will take a look

Tammi Carter
Tammi Carter
5,360 Points

Oohhhhh πŸ˜ƒ.... Well that at least makes my brain feel better!!! I’m on slack but learning how to navigate all of my tools 🧰. STEVEN YOU ARE AWESOME β—οΈβ—οΈβ—οΈπŸ™ŒπŸΎ Thank you again!