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

Code works but won't show results still I type quit

This code works for me, but when I start inputting the names, it wont do anything till I type "quit". once I do that, it shows me all the names that are correct. It wont show them in the background like the video does. let me know if I'm making since.

var message = '';
var student = [
  {
    name: "John",
    Track: "Javascript",
    Achivement: "woot woot",
    point: 1025
  },
  {
    name: "smith",
    Track: "Javascript",
    Achivement: "woot woot",
    point: 1254
  },
  {
    name: "Carry",
    Track: "Javascript",
    Achivement: "woot woot",
    point: 1825
  },
  {
    name: "bob",
    Track: "Javascript",
    Achivement: "woot woot",
    point: 1925
  },
  {
    name: "Meow",
    Track: "PHP",
    Achivement: "woot woot",
    point: 2025
  }
];

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

while (true) {
  var studentName = prompt("What is the name of the student? <type quit to stop>");
  if (studentName.toLowerCase() === "quit" || studentName === null)
    {break;}

  else{
   for ( var i = 0; i < student.length; i++) {
     if (studentName === student[i].name) {
   message += "<h1>Name: " + student[i].name + "</h1>";
   message += "<p>Track: " + student[i].Track + "</p>";
   message += "<p>Achivement: " + student[i].Achivement + "</p>";
   message += "<p>Points: " + student[i].point + "</p>";
     print(message);
     };
   };
  };


}

for ( var people in student){
  console.log(student[people]);
};

1 Answer

Steven Parker
Steven Parker
243,656 Points

That's typical behavior for modern browsers.

I think when the video was made, it was more common for browsers to render the page and run the program at the same time, but now they generally only render the page after the program finishes.

In later lessons you'll learn much better ways to interact with the user using input fields that still work as they always did.