If Statement Olympics

If Statement Olympics

The exercise will get progressively harder. You should at least strive to get one medal, but please try to go the extra mile!

Also, feel free to practice using ternary statements for extra credit too!


Preliminaries

  1. Write an if statement that prints "is greater than" if 5 is greater than 3
  2. Write an if statement that prints "is the length" if the length of "cat" is 3
  3. Write an if/else statement that checks if "cat" is equal to "dog" and prints, "not the same" when they are not equal.

Bronze Medal

  1. Using the below object, write an if statement that prints <theNameOfThePersonInObject> is allowed to go to the movie if they are old enough (18 or older), and the opposite if they are not older than 18.
var person = {
  name: "Bobby",
  age: 12
}
  1. Using that same object, only allow them into the movie if their name starts with "B"
  2. Using that same object, only allow them into the movie if their name starts with "B" and they are older than 18.

Silver Medal

  1. Write an if/else if/else statement that prints "strict" if 1 strictly equals "1", prints "loose" or "abstract" if 1 == "1" , and prints "not equal at all" if it doesn't print the other stuff.
  2. Write an if statement that prints "yes" if 1 is less than or equal to 2 AND (&&) 2 is equal to 4

Gold Medal

Gold may take some googling!

  1. Write an if statement that checks to see if "dog" is a string
  2. Write an if statement that checks to see if "true" is a boolean
  3. Write an if statement that checks to see if a variable has been defined or not
  4. Write an if statement asking if "s" is greater than 12?

Try it with a few more letters and a few numbers.

  1. Write a ternary statement that console.logs whether a number is odd or even. For example:
var myNum = 10;
// Write your ternary here to log if `myNum` is odd or even.

(It should continue to work correctly even if myNum changes to a different number).