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 Multiple Items with Arrays Useful Array Methods

I have two questions regarding this Lesson. 1. About the empty Search variable, 2. Why dont we use FOR Loop.?

I have two questions regarding this Lesson.

  1. About the empty Search variable, Why do we have to enter an empty search variable in the end.
  2. Why dont we use For Loop, and how do we use it.?
  3. My code does not prints the message just as in the tutorial. It does it only when I 'quit' the loop. Why is that.?

Please help

3 Answers

Henrik Christensen
seal-mask
.a{fill-rule:evenodd;}techdegree
Henrik Christensen
Python Web Development Techdegree Student 38,322 Points

About the empty Search variable, Why do we have to enter an empty search variable in the end. the search variable is being declared at the beginning because it's going to be used multiple places (going to make sense when you learn about scope)

Why dont we use For Loop, and how do we use it.? because a for-loop only runs x-times and a while-loop runs until it's told to stop.

My code does not prints the message just as in the tutorial. It does it only when I 'quit' the loop. Why is that.? kinda hard to tell because you didn't provide any code :-)

Can you please explain a lil bit ; why do we use empty search variable in the beginning.?

My code does not prints the message just as in the tutorial. It does it only when I 'quit' the loop. Why is that.?

https://w.trhou.se/nhteg4ilcg

Just by looking at your code, it looks like the search variable was not declared in the beginning. if your search is not declared with the var keyword, then your while condition is not going to work.

pat barosy
pat barosy
6,759 Points

I'm also having trouble understanding empty variables. How am I supposed to know when to use them in my code?