let myObj = {
name: 'Miti',
sayHello() {
return '${this.name} says hello!'
}
};
console.log(myObj.sayHello());
:star2: 3426 | @khaduch |http://www.freecodecamp.com/khaduch
:cookie: 267 | @kingcyrus |http://www.freecodecamp.com/kingcyrus
:cookie: 160 | @leeconnelly12 |http://www.freecodecamp.com/leeconnelly12
:star2: 3427 | @khaduch |http://www.freecodecamp.com/khaduch
:star2: 3428 | @khaduch |http://www.freecodecamp.com/khaduch
@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 console.log(x);
@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 return undefined;
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.