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
Alex Flores
7,864 PointsJavascript program flow in a loop and how to "reset" a variable?
I just wrote my question and lost it because I accidentally clicked outside of the modal.... Ok, real quick... Here's my code:
while (true) {
search = prompt('Search student records:');
if (search === null || search.toLowerCase() === 'quit') {
break;
}
// for loop to cycle through the students array to match with the users search
for (var i = 0; i < students.length; i++) {
student = students[i];
results.pop(students);
if (student.name.toLowerCase() === search.toLowerCase() ) {
results.push(student[i]);
message = getStudentReport(student);
print(message);
}
if (results.length < 1) {
message = "<h2> Sorry, that person does not exist in our records. </h2>";
print(message);
}
}
}
I'm trying to "reset" the results variable, but it just messes up the operation. I have two questions:
Can I reset a variable after the loop has run so that when it runs again the variable doesn't have a value? FIGURED IT OUT
Does anyone know of any good places to get a good understanding of the program flow or how the computer reads javascript?
Thanks!
EDIT: I FIGURED IT OUT!! Feels good man. Question two still remains. I'd love to learn how the computer reads the script in more detail.
1 Answer
Tommy Choe
38,156 PointsHey Alex,
I think I may have found a good link for you to look through. You might have to do some digging though.
http://stackoverflow.com/questions/3440198/how-do-javascript-interpreters-engines-work
Hope that helps!
Alex Flores
7,864 PointsAlex Flores
7,864 PointsThanks Tommy!