Arrow function and Ternary (if/else) operations

Hello, how is everybody?

I was experimenting with arrow function notation and ternary operations (if/else) to see if I understood them, but I can’t make this code work. It’s not in any particular exercise, but I think the category is functions, at the very beggining of the Full-stack Engineer path. (link)

let result = 0;

const multiplier = (num1, num2) => {

result = num1 * num2;

return result;

result > 20 ? console.log(‘This is a big number’) : console.log(‘This is a small number’);

};

multiplier(4, 4);

The goal here is to make a function that takes 2 parameters and multiplies them. If the result is greater than 20, it prints “This is a big number”, if it’s not, it prints (“This is a small number”), it’s just a silly starter function.

But I can’t get it to work, everytime I call the function nothing gets printed in the console.

What am I doing wrong?

Thanks!

Indentation is not the problem, these three lines are indented in the code.

Indentation is not relevant for the functionality of the code in Javascript. It is important for readability.

Nothing after a return statement within the function body is executed. Just switch the order of your return statement and the line with your ternary.

1 Like

Thank you! It worked now! :sweat_smile: :partying_face:

1 Like