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

Alexandra Wakefield
Alexandra Wakefield
1,866 Points

I'm So Confused

While doing this challenge, I am running into all sorts of problems.

For one, it's like the if statement within the for loop is being ignored when it comes to breaking out of the while loop. I've tried break, false, and even making an outside variable equaling true so I can change it to false if the if statement happens. However, it obviously works because the html variable prints to the page.

Two, I have no idea where or how to add alert("Sorry, this name is unavailable") to where it works properly. It either shows up no matter what I put in, creates an endless loop, or shows up until the for loop either completes or has a chance to repeat.

I'm lost.

Here's what I have currently:

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

var html = "";

function studentReport() {
  while(true) {
    var studentRequest = prompt("Please enter the student's fullname below or \"quit\" to exit.");
    var studentName = studentRequest.toLowerCase();
    for(var j = 0; j < students.length; j++) {
      var student = students[j].name.toLowerCase();
      if(studentName === student) {
        html += "<b>Student: " + students[j].name + "</b>";
    if(studentRequest === "quit") {




Julian jackson
Julian jackson
6,285 Points

Hi Alexandra,

It looks like you haven't declared your "students" array globally or within your function but it's called for in your for loop? not sure if that helps.


1 Answer

Thomas Nilsen
Thomas Nilsen
14,957 Points

Check out these answers.

They should help you.