CONTROL FLOW Comparison Operators


#1

https://www.codecademy.com/courses/learn-javascript-control-flow/lessons/control-flow/exercises/comparison-operators?action=lesson_resume&course_redirect=introduction-to-javascript

Hi!

I’m not having a problem per se but I wanted to know about the if (!hungerLevel > 7) statement. Is the ! evaluating the truthiness of hungerLevel variable or the whole statement?

Thanks you!

let hungerLevel = 10;

if (!hungerLevel  > 7) {
  console.log(`Time to eat!`);
} else {
  console.log(`We can eat later!`);
}

#2

! simple changes false to true and versa, hungerLevel > 7 is true given hungerLevel = 10, so then we get:

if (!true)

which becomes false


#3

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