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

Kamontat swasdikulavath
Kamontat swasdikulavath
2,447 Points

Why is my answer compiling and shows only after i press quit?

var students =[
  {name:"DAVE",Track:'Web developer', Achievement:434 ,Points:432},
  {name:'ROBERT',Track:'killer', Achievement:343 ,Points:345},
  {name:'ERIC',Track:'scientist', Achievement:34 ,Points:432},
  {name:'OSTA',Track:'app maker', Achievement:2342 ,Points:2342},
  {name:'ELISE', Track:'Front end dev', Achievement:123,Points:314}





]
var HTML=' ';
var message = '';
function print(HTML){
var outputDiv = document.getElementById('output');
outputDiv.innerHTML = HTML;

}
function List(i){
HTML += '<ol>'  
HTML +='<li><h2>Name: '+students[i].name+'</h2></li>'
HTML +='<li>Track: '+students[i].Track+'</li>'
HTML +='<li>Achievements:'+students[i].Achievement+'</li>'
HTML +='<li>Points: '+students[i].Points+'</li>'
HTML +='</ol>'
return HTML;
}

while(true){

var UserInput=prompt("What is your name, type your [name][Dave, Osta, etc] and then type [quit] to see your info");
if (UserInput.toUpperCase() === students[0].name){
print(List(0));
}
else if(UserInput.toUpperCase() === students[1].name){
print(List(1));
}
else if(UserInput.toUpperCase() === students[2].name){
print(List(2));
}
else if(UserInput.toUpperCase() === students[3].name){
print(List(3));
}
else if(UserInput.toUpperCase() === students[4].name){
print(List(4));
}
else if(UserInput.toUpperCase() === 'QUIT'|| UserInput===null){
  break;
}
  }

the answer doesn't disappear like the video said it will. It compiled one after the other instead. Is this because of the webbrowser being changed after this video was made?

Adrien Contee
Adrien Contee
4,875 Points

Your code isn't maintainable. You should really use a 'for loop'. Just my two cents.

1 Answer