More on Control Flow 13/14


#1

I got it right but I don't get why it works.

If it's asking me to make it so that the program returns true when programming is false, then shouldn't "!programming" = true? so it should return false instead of true?

programming = false
so
!programming = true
so shouldnt the code return false when plugging in "!programming"(true)?


// Declare your variables here!
var programming = false

var happy = function() {
  // Add your if/else statement here!
  if(!programming){
      return true;
  }
  else{
      return false;
  }
};

happy();


#2

Programming is false, so if programming isn't true, (which it's not), happy will return true. I know it's a little bit crazy to understand, but that's just the logic of the program.


#3

Went straight to bed after this lesson...


#4

With my limited knowledge of JavaScript, I think the if statement is testing the condition. If the condition passes the test (Is programming false, true?) if yes, it will run the first return statement. I think that's what is happening. I think I just confused myself with this one. Okay, anyone else want to have a go at explaining this code? I would love to hear an expert try. I think I'm going to do what that other guy did. Go straight to sleep! Hahaha


#5

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