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 trialSaif Kbishi
Front End Web Development Techdegree Student 11,904 Pointshi 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
231,248 PointsWhen posting code, use the instructions for code formatting in the Markdown Cheatsheet pop-up below the "Add an Answer" area. 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.
Saif Kbishi
Front End Web Development Techdegree Student 11,904 PointsSaif Kbishi
Front End Web Development Techdegree Student 11,904 PointsWOW, thank you very much. that was the problem. i will watch video