Ternary expression exercise 5/11

The exercise I did was 5/11 control flow

I would like to know why my code is not being accepted

// this is codecademy's own code
let hungerLevel = 10; 
if (hungerLevel > 7) {
  console.log('Time to eat!');
} else {
  console.log("Let's eat later!");

// this is my if statement
console.log (hungerLevel > 7 ? "Time to eat!" : "We can eat later!" )

the exercise check if if and else are present, this is not the case with a ternary operator.

1 Like

why did the earlier comparison tasks then work with ternary statements?

maybe there the validation worked differently. Validating code can be done several ways, depending on how the validation is coded, which alternative approaches work

for example, if the validation runs your code, and checks that for different values of hungerLevel the correct string is logged to console, then the ternary operator would work

but if the validation check the presence of if keyword then ternary operator won’t work


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