The way that programs make decisions is called **control flow**. The most common way to make decisions is with an `if` statement. An `if` statement only runs code if a certain `condition` is true. For example, your condition could only make fun of people who are older than, like, arbitrarily, 29 years old. ```javascript if (age > 29) { console.log('Unc alert!!') } ``` You might also want to run some code if the condition is not true. ```javascript if (age > 18) { console.log("Hey, you can vote!") } else { console.log("Hah, you're a child.") } ``` You might also find yourself in a situation where you need a few more options than `if` and `else`. In that case, you probably want to say something like "if this …, else if this …, else if this …, or if all of those are false do this." Luckily, we can use `if`, `else if`, and `else` to do that. ```javascript if (age > 65) { console.log("Bruh, you're literally a dinosaur") } else if (age > 40) { console.log("Please stop asking me how to use your phone") } else if (age > 28) { console.log("Unc status") } else if (age == 28) { console.log("Nice. You're literally the perfect age") } else if (age > 18) { console.log("Hey, since you can vote, can we get some more bike lanes?") } else { console.log("What's your favorite food? Apple sauce or milk?") } ``` > [!WARNING] WARNING! WARNING! WARNING! > Look out! "else if" only gets checked if the statement before it fails. > You're probably gonna do something silly at some point like this: > ```javascript > if (grade > 85) { > console.log("You're Proficient!") > } else if (grade >= 100) { > console.log("You're Excel!") > } else { > console.log("NYP. Booooo") > } > ``` > This program will never notice you're Excel, because it checks if you're Proficient first. ## instructions **Challenge 1** In chemistry, pH is a scale that measures how acidic something is. It goes from 0 to 14. Anything less than 7 is acidic. Anything above 7 is basic. If a solution is 7 exactly, it's neutral. > Create a program that takes in a pH value and tells you if it's acidic, basic, or neutral. --- **Challenge 2** It will be useful to get a random number for this one. You can do that like this: ```javascript Math.floor(Math.random() * 101); ``` `Math.random()` generates a random number between 0 and 1 (but never exactly 0 or exactly 1) `Math.random() * 101` makes that random number somewhere between 0 and 101 `Math.floor( … )` rounds that down to a whole number (now 0 to 100) > Create a magic 8 ball program that takes in a yes or no question and gives you a random answer. > Your program should have 9 possible ansers: 3 ways to say yes, 3 ways to say no, and 3 ways to say it's not sure > It should output something like this: > ```plaintext > Question: [question] > Magic 8 Ball: [answer] > ``` --- **Challenge 3** When you're creating an if statement, you can check multiple conditions at once like this: ```javascript if (age > 12 && age < 20) { console.log("You're a teenager") } ``` > Create a program that determines if a person is allowed to get on a rollercoaster. > You must be at least 5' tall and have 10 credits to ride the coaster. > Ask the person their height and how many credits they have, and give them a message telling them *why* they can or cannot get on the ride.