Ternary expression exercise 5/11


#1

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!" )

#2

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


#3

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


#4

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


#5

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