Call the function inside itself

can i not call the function inside itself? :grimacing:

let myFuncVariable = function(n){
  if(typeof n === "number"){
    return n*3;
  }else{
    let readlineSync = require("readline-sync");
    let input = readlineSync.question("try using a number ")
    return myFuncVariable(input);
  }
}


myFuncVariable('aklsdjf');

You can definitely call a function within itself.

I tried running your code, and it does run without any errors. However, it doesn’t work as you intend due to the conditional check in the first line of the function. The parameter n will always be of type string if it is the result of calling readlineSync.question, since that method always returns a string. So you’ll need a different type of conditional check to determine of n is a number in this case.