Function Declarations

What is wrong with my code? Why do i get a false?

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



Remember to include the arguments, 4 & 2 (or whatever).

1 Like

I feel that you might have been trying to use your second to last line of code to declare and calculate the parameters and then used the last line to log the result in the console. It won’t work because when you use return in your function’s block, you have to use console.log to call the function and pass the parameters you want the function to calculate i.e. console.log(isGreaterThan(4, 2));. Check out the code below:

function isGreaterThan(numberOne, numberTwo){
if(numberOne > numberTwo){
return true; //If you used console.log(true); this would have been fine with your second to last line of code.
} else {
return false; //Just as above, If you used console.log(false); this would have been fine with your second to last line of code.
//The code below doesn’t log anything on the console because there is no console.log code telling it to. This line wasn’t necessary.

isGreaterThan(4, 2);

// The following code returns ‘false’ and I feel it is because there are no parameters listed so it’s not truthy; therefore, it has to log a result of false. However, you were close. You just needed to pass in the parameters.


//The following code logs in the correct result.
console.log(isGreaterThan(4, 2));

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