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

illegal break statement, any idea way? if(search===null || search.toLowerCase() === 'quit'){ break;}

var message;
var student;
var search;

function studentReport(student){
var report='student: ' + student.name;
    report+='student: ' + student.age;
    report+='studnet: ' + student.skills;
    return report;
}

students=[
{name: 'beth', age:22, skills:['java', 'ois']},
{name: 'seth', age: 30, skills: ['ruby', 'python']},
{name:'david', age:26, skills:['java', 'nod.js']},
{name: 'john', age: 20, skills: ['pyhon', 'javascript']},
{name: 'brittany', age: 40, skills: ['javascript', 'nod.js']}
];

while(true){
search=prompt("what is the student's name, type quit to exit");
}
if(search===null || search.toLowerCase() === 'quit'){
break;}

for (var i=0; i < students.length; i+=1){
  student= students[i];
if(student.name===search.toLowerCase()){
  message= studentReport(student);
console.log( message);
}

1 Answer

akak
akak
29,445 Points

break statement needs to be inside of a loop. You're closing the loop before that

while(true){
    search=prompt("what is the student's name, type quit to exit");
} // while loop closed here

if (search===null || search.toLowerCase() === 'quit'){
    break;
}

also have in mind that your search won't be null if it's empty. It'll be just an empty string which is falsy. So your check should look like

if (!search || search.toLowerCase() === 'quit')