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

evans tsai
evans tsai
3,735 Points

Student record search challenge

Umm... When I practice this challenge , and I met some problem. The code can work, but the most weird is that when I enter the name into the pop out box (prompt), the result will not show on the screen. but when i press the esc to cancel the pop out box , the result show!! It's different from the video! And I don't know where is the problem. plz help me.

var students = [
  {name: "Andy", track: "bussiness", achievement: 3, point: 60},
  {name: "Evans", track: "js, python", achievement: 5, point: 99},
  {name: "Yanzhi", track: "sleep", achievement: 5, point: 100},
  {name: "Scout", track: "masterbate", achievement: 2, point: 40},
  {name: "Brad", track: "trashtalk", achievement: 4, point: 87},
];
var message= '';
var student;
var answer;

function print(message) {
  var outputDiv  =document.getElementById('output');
  outputDiv.innerHTML = message;
}
function getstudentinfo(){
  var info = "<h2>student: " + student.name + "</h2>";
  info += "<p>track: "+ student.track + "</p>";
  info += "<p>achieve: "+ student.achievement + "</p>";
  info += "<p>point: "+ student.point + "</p>";
  return info;
}
//  
//for(i = 0 ;i < students.length; i+=1){
//  student = students[i];
//  message += "<h2>student: " + student.name + "</h2>";
//  message += "<p>track: "+ student.track + "</p>";
//  message += "<p>achieve: "+ student.achievement + "</p>";
//  message += "<p>point: "+ student.point + "</p>";
//}
//print(message);


while(true){
  answer = prompt("who do u want to search for?");
  if (answer===null || answer.toLowerCase() === "quit"){
  break;
  }
  for(var i = 0; i < students.length ; i +=1 ){
    student=students[i];
    if(student.name === answer){
      message = getstudentinfo(student);
      print(message);
    }
  }
}

2 Answers

What browser are you using? Is it Google Chrome? I have tested your code and it is working fine, the first answer is right about the comma but it doesn't stop your code from working. The results you describe are what happens in Chrome, and I noticed this when I did the exercise, try Firefox and you should see it works as the video. Chrome works differently to Firefox.

evans tsai
evans tsai
3,735 Points

yup! It's only happen when I use chrome. It works in firefox. So it's because of the default of browser, instead of the code itself???

I only see one error. At line : {name: "Brad", track: "trashtalk", achievement: 4, point: 87}, You should not write comma at the end of this line.

If this would not help I am not sure what is wrong for that moment.

Cheers

evans tsai
evans tsai
3,735 Points

thank u! I think it may because the browser's setting!