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

brandonlind2
brandonlind2
7,823 Points

why arent the results in the for loop being print to the console?

javascript
var students= [
  {   name: "Sarah",
   track: "ios",
   achievements: 20,
   points: 50
  }, {
   name:"tom",
   track: "frot end programming",
   achievements: 40,
   points: 60
  },  {
   name: "Bob",
   track: "java",
   achievements: 60,
   points: 70
  }
];
function print(message){
  console.log(message);
}
while(true){
var search= prompt("Type student name for info");
if(search === null || search.toUpperCase === "quit"){
    break;}
}
for(i=0; i < students.length; i+=1){
    if(search.toUpperCase() === students[i].name){
    var message=student.name + " " + 
          student.track + " " +
          student.achievements + " " +
          student.points;
     print(message);
   }
}
Ham Hamey
Ham Hamey
5,712 Points
<script>
function print(message){
  console.log(message);
}

  var students= [
  {   name: "Sarah",
   track: "ios",
   achievements: 20,
   points: 50
  }, {
   name:"tom",
   track: "frot end programming",
   achievements: 40,
   points: 60
  },  {
   name: "Bob",
   track: "java",
   achievements: 60,
   points: 70
  }
];

//print(students[2].name);


while(true){
var search= prompt("Type student name for info");
  //alert(search);
if(search === null){
   break;}

else{
for(i=0; i < students.length; i+=1){
    if(search.toUpperCase() === students[i].name.toUpperCase()){
    var message=students[i].name + " " + 
          students[i].track + " " +
          students[i].achievements + " " +
          students[i].points;
     print(message);
   }
}
}
}
</script>

There were many typos in your code like student instead of students and while comparing in the if statement

Gavin Ralston
Gavin Ralston
28,770 Points

Also, beware this code here: It's not going to do what you probably intended. You'll never match "quit" to an uppercased version of anything. :)

if(search === null || search.toUpperCase === "quit") { break; }