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 trialSaud Tauqeer
Courses Plus Student 8,099 PointsSome confusions
So the code goes like this First in the for loop we assign {Student = student [i]} Now after the for loop we put conditions In the for loop we put a while condition for null or βquitβ break point. Now we put another condition Response === student.name { GetstudentFunction(student) } Now this student function has that writes a formated html with names and values. Like <h1 student name: <h1> + student.name So this function will run when response === student.name My confusion is the loops. So whenever there is a student.name = response The loop will stop with whatever [i] value in student has. Such as if we had searched for dave and its in the student[1].name So now student stores value of student[1] = student Now when we put it like this Function getstudent (student) Now the parameter = to the student [1] right? So it will print all the values via the func such as student.points and etc. Now how will we print the same names as he tells in the video and how can we show the name Without hitting quit. I know this is a rant and i should include a code but i thought i can ask to the point like this
1 Answer
Steven Parker
231,269 PointsIf I understand, you're asking about why you must enter "quit" before seeing your previous selection. This is discussed under "Important Update" in the Teacher's Notes section of the video:
Most browsers ... wait until the loop finishes and then they print to the window. So, you'll see a blank page until you type quit in the prompt window β then you'll see all the output printed to the screen.
This is a limitation of the "prompt" method, which is almost never used in actual development. As you continue in the courses, you'll learn other ways to make your pages immediately responsive using input elements and event handlers.
Saud Tauqeer
Courses Plus Student 8,099 PointsSaud Tauqeer
Courses Plus Student 8,099 PointsCAN you tell me about how can i display two arrays with same names
Saud Tauqeer
Courses Plus Student 8,099 PointsSaud Tauqeer
Courses Plus Student 8,099 PointsOne thing i have in mind is that Lets say user searche for dave which is Student[1].name Now the i = 1 right now in the for loop. I add a statement that break write the details of i and then breaks. And somehow goes back into the loop again with the values next than 1 or current i value so it will display the other dave on student [2].name Is my understanding correct?
Steven Parker
231,269 PointsSteven Parker
231,269 PointsWithout seeing the code I can only guess why this isn't the way it works now. But perhaps the search is stopping when a match is found instead of continuing to look through the list. Or perhaps the output for each match replaces the previous one instead of adding to it.
Saud Tauqeer
Courses Plus Student 8,099 PointsSaud Tauqeer
Courses Plus Student 8,099 Pointshere's my code : https://w.trhou.se/i4i2atvunb
i dunno why its not working the way its supposed to be. this section is getting ignored for some reason if (studentFound === true) { break; }
if (noStudentFound === true){ alert ('No student named ' + search + ' was found. ' ); }
Steven Parker
231,269 PointsSteven Parker
231,269 PointsIt looks like you created tests instead of assignments in two places:
Saud Tauqeer
Courses Plus Student 8,099 PointsSaud Tauqeer
Courses Plus Student 8,099 PointsThank you
Saud Tauqeer
Courses Plus Student 8,099 PointsSaud Tauqeer
Courses Plus Student 8,099 Pointsso this break right here when the studentFound is true; if (studentFound === true) { break; }
so far i think that the break is supposed the stop the loop and will start again from the for loop which contains the value of i so if there are two dave one at [i] index [0] and the other at [i] index value 1 the function will break at 0 index's dave and when it runs again it already has the value of index 0 so it will go back again and check at 1 index or i value if there is another dave. and it prints out two daves. is my understanding about break function is wrong? please give me a brief explanation whats really happening here in the loop and how are two daves printing out
Saud Tauqeer
Courses Plus Student 8,099 PointsSaud Tauqeer
Courses Plus Student 8,099 Pointssteven are you there?
Steven Parker
231,269 PointsSteven Parker
231,269 PointsThe two "Dave"s are found by the "for" loop.
The "break" is after the "for" loop, and it stops the "while" loop. That's why you don't have to type "quit" when it finds anything.
Saud Tauqeer
Courses Plus Student 8,099 PointsSaud Tauqeer
Courses Plus Student 8,099 Pointsty