Question about true/false (7. function declarations)


#1
function isGreaterThan (numberOne, numberTwo){
  if(numberOne > numberTwo){
    return true;
  } else {
    return false;
  }
}

isGreaterThan(5, 1);
console.log(isGreaterThan());

This returns false in the console even if I change 1 and 5 and 5 and 1. The lesson says I passed but I’d rather not move on until I know why it won’t change to true.

Edit: Asked a co-worker and the reason is because the you’re not calling an actual function since you’re comparing null to null. You have to store the function in another variable like

var result = isGreaterThan(1,5);
console.log(result);

And that will get you the correct results.


#2

You should pass two parameters here


#3

isGreaterThan(5, 1); // This executes the function but there is no output command. So delete this.

console.log(isGreaterThan(5, 1)); // This executes the function with the arguments and prints the result on console.


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.