Let's do some conditional statements and compound operators cardio!
GOAL: On the script.js
file you will see 6 challenges that you need to complete for today. These challenges ask you to use some combination of conditional (if/else if/else) statements and compound operators (&&
, ||
, `!'). Completing all 6 of these practice problems today will help you to lock in this core programming structure that we will utilize throughout the rest of this course!
Open the script.js
file to see all of the directions for today. To get user input, you should utilize the prompt()
command. An example of this is shown below:
//Ask the user for their name and save the value in the variable name
var name = prompt("What is your name?");
- Ask the user to input a temperature. Return the following message based on the input
Temperature | Output |
---|
100 | Tell them it's too hot to go outside | 80 - 100 | Tell them to bring a water bottle to stay hydrated| 60 - 80 | Tell them to bring a water bottle to stay hydrated| Less than 60 | Tell them to bring a jacket |
- The MTA is switching to charging based on how far you travel rather than a flat fare (similar to how DC is). Ask the user to input how many stops they will be traveling and print out the price based on the following guidelines.
Number of Stops | Output |
---|---|
0 - 5 | $1.50 |
5 - 15 | $2.50 |
15 - 20 | $3.00 |
20 | $3.50 |
-
Uncomment the lines under #3 on
script.js
. If the day of the week is Thursday AND they are younger than 18, tell them that they get free admission to the museum. Otherwise, tell them they need to pay the full price of admission. -
You are applying for a scholarship. The scholarship requires that you have above a 3.0 GPA and above a 1100 on the SAT. Write a program that: (a) Asks the user for their GPA (b) Ask the user for their SAT score (c) Prints out (1) "You can apply!" if they meet both requirements, (2) prints out "increase your GPA" if they are just missing the GPA requirement, (3) prints out "increase your SAT score" if they are just missing the SAT requirement, and (4) prints out "increase GPA and SAT" if they are missing both requirements.
-
Ask the user to put in the current temperature. Ask them also to put in the current weather (e.g. sunny, rainiy, snowing, etc). If it is below 30 degrees or it is snowing, tell them they need to bring warm clothing today. If it is below 50 degrees or it is raining, tell tem to wear a jacket. Otherwise, tell them that it looks like a good day outside.
-
Ask the user the day of the week and their age (you can use a previous age variable if you prefer). If it is Saturday or Sunday and they are a teenager, tell them they can sleep in. If it is not Saturday or Sunday (i.e. it's a school day) and they are a teenager, tell them to go to school. If they are not a teenager and it is not a weekend, tell them to go to work.