Function Expression

I don’t understand where am i making mistake ?

const plantNeedsWater = function(day) {
 day === 'Wednesday' ? return true : return false;
};

console.log(plantNeedsWater('Wednesday'));

It gives token error message in output.

You are misunderstanding the use of the conditional ternary operator. The true and false expressions are values that will be returned by the operand, so there is no need of typing return in the expression.

To understand better how the ‘conditional ternary operator’ works as well as its syntax don’t forget to go to the documentation. There you can find a lot of sample code to guide you. How to use the conditional ternary operator

1 Like

operands don’t return anything, they are terms in an expression.

    day === 'Wednesday'
    /             \
operand        operand

The returns are needed but since the ternary is itself an expression, we can return it.

return day === "Wednesday" ? true : false;

Aside

When the return values are themselves boolean primitives, we can return the truth value of the conditional expression without resorting to more logic.

return day === "Wednesday";

but the practice with a ternary expression may be the point of the exercise so we should not disregard that.

2 Likes