JavaScript JavaScript Loops, Arrays and Objects Tracking Data Using Objects The Student Record Search Challenge Solution

Saif Kbishi
Saif Kbishi
Front End Web Development Techdegree Student 5,785 Points

hi why does the code inside my IF condition is not executed? see comments inside

while(true){ search = prompt('which student you are looking for?'); console.log('1 '+search); search = search.toLowerCase(); console.log('2 ' +search); if(search === 'q'){break;} else { console.log('1a'); for(var i=0; i<students.length; i+=1) { student = students[i]; console.log(i); //printed in the console console.log(student.name); //printed in the console if(student.name === search) { /*this is NOT executed */ console.log('2a'); console.log('yes'); var message =''; message += '<p> my name is '+ student.name + ', im in track ' + student.track + ', i got ' + student.achievements + ' achievements and ' + student.points+ ' points </p>'; print(message); console.log(message); } } } }

1 Answer

Steven Parker
Steven Parker
127,593 Points

When posting code, use the instructions for code formatting in the Markdown Cheatsheet pop-up below the "Add an Answer" area. :arrow_heading_down:   Or watch this video on code formatting.

This program relies on the contents of a "students" array, which is not shown here, so the reason for your issue cannot be determined exactly. But I can make a guess — I noticed that the search term is converted into lower case, so if the names in the "students" array are not stored in all lower case, they will not match.