Undefined on Function Call

function greatestNumber(num1, num2) {
  if (num1 > num2) return num1;
  num2;
}

let number = greatestNumber(2, 3);

console.log(number);

Trying to run this but I am getting undefined. Why is this happening?

num1 is not greater than num2, so you don’t return anything, you’re only returning something if num1 is greater than num2.

Hello there.

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.

Note: Backticks are not single quotes.

markdown_Forums

To answer your question: 2 is not > 3. Therefore, your function does not return anything, because you have not told it to return anything, if that is the case. So, number gets assigned undefined.

Hope that helps

I am missing a return statement. I see thank you.