@xtine88 - the definition of
0! is that it is equal to 1. If the incoming value is
0 your loop will never run, so the value will remain at
1 and that is what you want to return. That's the main reason.
And to complete the function you have to actually do
return x; after the loop, at the same place you have
@xtine88 - no,
console.log(x) doesn't return a value from the function, it might return a value (probably a meaningless one) to the place where you called console.log, but for all intents and purposes, it doesn't return a value. Especially not from the function. You can leave it there for debug purposes, but you have to have an explicit
return x; otherwise you get an implicit
And you could look at
var x = 1; as a way to enter the loop - initializing the value, but since it isn't really a loop-control value, maybe it's not technically correct to call it anything having to do with entering the loop. Basically I would just think of it as initialization of the variable. And if you do no further computation to modify the variable, that will be the final answer.
<ul style="list-style: none;"> <li class="list-txt">What does she do?</li> <li class="list-txt">Sits on a guy's shoulder. </li> <li class="list-txt">does angry lala noises </li> <li class="list-txt">trusts you </li> <li class="list-txt">What she doesn't do: <li class="list-txt">tall people that isn't her personal portable chair </li> <li class="list-txt"> tall people who don't pet her before speaking</li> <li class="list-txt"> tall people who look down at her</li> </ul>