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
Henrik Christensen
Python Web Development Techdegree Student 38,297 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

Stephen Chamroeun
Stephen Chamroeun
4,911 Points

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?