What's wrong with this code?

Here is the link to the question
Here is my code

function order (number, flavor) {
  if (number == 1){
    return console.log(`Lemme get ${number} scoop of ${flavor}!`);
  } else {
    return console.log(`Lemme get ${number} scoops of ${flavor}!`);
  }
}
order(1, 'vanilla');
order(3, 'chocolate');

when I run the code in Firefox console it seems to give the desired results.
But this is what Codecademy IDE says

We invoked your function with the arguments 1 and "vanilla" and expected it to return "Lemme get 1 scoop of vanilla!" . Instead it returned: "undefined"

Not sure why?

Hi,
while your function runs, it logs the desired result. Because you console.log() within the function scope.
But what is returned to the function call is ‘undefined’, because you return ‘console.log()’ and console.log() returns ‘undefined’.
The solution would be not to log the string inside the function body but just to return the string. And then log the function call.

Oh, I see.
Thanks for your reply.

1 Like