-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathconditionals.js
132 lines (96 loc) · 5.64 KB
/
conditionals.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/* ==== WARM-UP SET 1 ====
Directions: Replace the blanks '__' for each of the `console.log()` statements below with comparison operators (>, <, >=, <=, ===, !==). The goal is to make each statement print a value of `true` to the console. Be sure to uncomment each statement before pressing the `run` button. Test each statement before moving on to the next one. Feel free to comment out any previous code if the console becomes crowded. (Helpful Tip: try to use a different comparison operator each time.)
*/
/*
Example:
console.log(45 __ 45)
*/
// Solution:
console.log(45 === 45)
// console.log(-9 __ 9)
// console.log(100 __ 100000)
// console.log(5.6 __ 5.5)
// console.log("hello" __ "dog")
// console.log("Danny" __ "Danny")
/* ==== WARM-UP SET 2 ====
Directions: Replace the blanks '__' for each of the `console.log()` statements below with comparison operators (>, <, >=, <=, ===, !==). The goal is to make each statement print a value of `false` to the console. Be sure to uncomment each statement before pressing the `run` button. Test each statement before moving on to the next one. Feel free to comment out any previous code if the console becomes crowded. (Helpful Tip: try to use a different comparison operator each time.)
*/
/*
Example:
console.log(2 __ 10)
*/
// Solution:
console.log(2 > 10)
// console.log(2 __ 10)
// console.log(22 __ 22)
// console.log( 0 __ -5)
// console.log(3.3 __ 3.5)
// console.log("frog" __ "prince")
/* ==== EXERCISE 1 ====
Directions: Replace the blank after the word `if` with a conditional statement so that the lunch invitation is only printed if the variable `isHungry` is true. Change the boolean value of the isHungry variable to check and see if your conditional statement works. (Helpful Hint: Don't forget to uncomment the code below to test your conditional statement!)
*/
let isHungry = false
// if (__________) {
// console.log("Do you want to grab some lunch?")
// }
/* ==== EXERCISE 2 ====
Directions: Begin by assigning the variable,`firstNumber` a positive or negative number. Then, replace the blank after the word `if` with a conditional statement that tests to see if the number stored in the variable is positive or negative. Make sure to change the value of `firstNumber` to ensure that your conditional statement works for (+) or (-) numbers!
(Helpful Hint: Think of a number line (or Google it!). The number 0 is neither positive nor negative. If a number is greater than 0, then it is considered a positive number...)
*/
// let firstNumber = ______
// if (__________) {
// console.log("That number is negative!")
// } else {
// console.log("That number is positive!")
// }
/* ==== EXERCISE 3 ====
Directions: Begin by assigning the variable,`secondNumber` a random number. Then replace the blank with a conditional statement that tests to see if a number is even. Make sure to change the value of `secondNumber` to ensure that your conditional statement works for both even and odd numbers!
(Helpful Hint: The % (remainder or modulus) operator might be useful here. When an even number is divided by 2, the remainder is 0. Can the same be said about odd numbers?)
*/
// let secondNumber = ______
// if (__________) {
// console.log("That number is even!")
// } else {
// console.log("That number is odd!")
// }
/* ==== EXERCISE 4 ====
Directions: Replace the blank below with a conditional statement that only adds a fee to the ticket price if the luggage weight is over 50 pounds. Update the console.log() statements by concatenating the variable `ticketPrice` to let the customer know the total price of their trip. Change the value of `luggageWeight` to check that all conditions work for the code below.
*/
// let luggageWeight = 55
// let ticketPrice = 150
// if (__________) {
// ticketPrice += 20
// console.log("An extra $20.00 fee was added to the plane ticket for going over the maximum weight.")
// } else {
// console.log("No extra fees, have a nice flight!")
// }
/* ==== EXERCISE 5 ====
Directions: Begin by assigning the variable `carSpeed` a number. Replace the blanks with a conditional statement that prints the correct statement depending on the carSpeed that you input.
(Helpful Hint: Consider which logical operators would best help you compare `carSpeed` with the min or max speed limit values.)
*/
// let carSpeed = _____
const maximumSpeed = 70
const minimumSpeed = 45
// if (__________) {
// console.log("Slow down, you're speeding!")
// } else if (__________) {
// console.log("Speed up, you're holding up traffic!")
// } else {
// console.log("You are at a great speed, just keep driving.")
// }
/* ==== EXERCISE 6: CHALLENGE ====
Write a conditional statement that mimics an automatic checkout machine at a store.
===== This example is pseudocode, but it describes what our challenge program should do! ======
if customerPayment is greater than the totalCheckoutCost, calculate the customer's change and print a statement like this:
Your change is $3.25. Thank you for shopping with us today.
if customerPayment is less than the totalCheckoutCost, calculate the remaining balance and print a statement like this:
There is still $2.75 remaining on your balance.
if customerPayment is equal to the totalCheckoutCost, print a statement wishing the customer a nice day like this:
Thanks and have a nice day!
Helpful Hint:
- There are multiple conditions needed for this exercise. Consider using `else if` as shown in exercise 5.
- There is some arithmetic involved. A remaining balance must be calculated along with how much change is due to the customer.
*/
// let customerPayment = _______
// let totalCheckoutCost = _______
// write conditional statement below: