JavaScript JavaScript Loops, Arrays and Objects Tracking Data Using Objects The Student Record Search Challenge Solution

michaelsherry
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
194,933 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
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
194,933 Points

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