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 JavaScript Loops, Arrays and Objects Tracking Data Using Objects The Student Record Search Challenge Solution

michaelsherry
seal-mask
.a{fill-rule:evenodd;}techdegree
michaelsherry
Full Stack JavaScript Techdegree Student 12,133 Points

Not showing any errors but also not working

I have written the code just like the instructor showed but when I run it shows a prompt but nothing works when entered into it. There are no errors being thrown either. Is there something I am missing in the code? I appreciate any help you can give me.

var message = "";
var student;
var search;

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

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

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

1 Answer

Steven Parker
Steven Parker
231,268 Points

Here's a few hints:

  • always use Markdown formatting when posting code
  • this code requires an array of "students" to work, but nothing by that name is defined here
  • a single "=" is an assignment operator, so the one in the "if" statement sets "search" to null
  • when invoking a method (such as "toLowerCase") you must put parentheses after the method name
  • when the other issues are fixed, remember that the browser will only render after you enter "quit"
michaelsherry
seal-mask
.a{fill-rule:evenodd;}techdegree
michaelsherry
Full Stack JavaScript Techdegree Student 12,133 Points

Thank you Steven! I didn't even see those mistakes :) And also thanks for the tip about Markdown formatting, I'll be sure to use that from now on.

Steven Parker
Steven Parker
231,268 Points

michaelsherry — Glad to help. You can mark the question solved by choosing a "best answer".
And happy coding!