‘function’ instead of ‘for’

I used ‘function’ instead of ‘for’ . First it logs what I wanted. Then it says ‘undefined’ MYYYNUMBER + 1 (That means eight) times. Why?

let MYYYNUMBER = 7;    //How many times it should log
let MYYYVALUE = 1;       //Value that is changed in loop and is printed                                                                           
var MYYFUNCTION999 = function MYYFUNCTION777() {  //Function starts
  if (MYYYNUMBER > 0) {         //Makes loop work until MYYNUMBER is 0
console.log(MYYYVALUE)       //Logs MYYYVALUE
    MYYYNUMBER--               //Makes the loop come to end by a little bit
    MYYYVALUE++                      //Makes loggable number bigger
    console.log(MYYFUNCTION999());     //Repeats the function 
  };     //END
};      //I won't stop commenting, you know...
console.log(MYYFUNCTION999());     //Starts the function
   //At the end output is what I wanted + 'undefined' 8 times. 
  //R.I.P. 12 year old from Lithuania. Died from rage. 2019-04-13. 

you log the result of the function call, but the function doesn’t return anything so undefined indicates the absence of a return value.

1 Like

I don’t know where should I put ‘return’ exactly. In which line should I do that?

PS.: Thank you for the answer.

The first question you should ask yourself: do you even want to use return? If you don’t want to use return you can also decide not to log the return value (or absence of return value)

1 Like

… I don’t understand? What should I exactly do with return and without it? What commands should I do?