mardi 1 mai 2018

return Nan from JavaScript object

why myTodos.meetDone() functions return Nan? it js of course and i just define an object called myTodos, and simply i wanna print console.log() the result.

let myTodos = {
day: 'Monday',
meetings: 0,
meetDone: 0,


addMeeting: function (num) {
    this.meetings = this.meetings + num;
},
meetDone: function (num) {
    this.meetDone = this.meetDone - num;
},
resetDay: function () {
    this.meetings = 0;
    this.meetDone = 0;
},
report: function () {
    let meetleft = this.meetings + this.meetDone;
    return `Yo have ${meetleft} meeting for today!`;
},
}
myTodos.addMeeting(2);
myTodos.addMeeting(5);
myTodos.meetDone(23);
console.log(myTodos);

console.log(myTodos.report());

and result is:

{ day: 'Monday',
  meetings: 7,
  meetDone: NaN,
  addMeeting: [Function: addMeeting],
  resetDay: [Function: resetDay],
  report: [Function: report] }
Yo have NaN meeting for today!

any way first console.log is for debugging why it's returning Nan i don't under stand this!!!!




Aucun commentaire:

Enregistrer un commentaire