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

Saif Kbishi
seal-mask
.a{fill-rule:evenodd;}techdegree
Saif Kbishi
Front End Web Development Techdegree Student 11,904 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
231,269 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.