-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.js
More file actions
64 lines (50 loc) · 2.32 KB
/
Copy pathscript.js
File metadata and controls
64 lines (50 loc) · 2.32 KB
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
// ============================================
// Unit 8.3 – Selection & Conditionals
// ============================================
// Complete each function below by following
// the STEP comments. Do NOT rename the functions.
// ============================================
// --- WARM-UP: checkNumber() ---
// This function checks whether a number is positive,
// negative, or zero.
function checkNumber() {
// STEP 1: Use prompt() to ask "Enter a number"
// Store the result in a variable using let.
// STEP 2: Use parseFloat() to convert the string to a number.
// STEP 3: Check if the input is not a number using isNaN().
// If it is not a number, alert exactly: "Invalid input"
// Then return (exit the function early).
// STEP 4: Use if/else if/else to check the number:
// If the number is greater than 0, alert exactly: "Positive"
// If the number is less than 0, alert exactly: "Negative"
// If the number is exactly 0, alert exactly: "Zero"
}
// --- ticketPrice() ---
// This function determines a ticket price based on the
// customer's age. Each age range has a different price.
//
// Child (0–12) → $7
// Teen (13–17) → $12
// Adult (18–64) → $20
// Senior (65+) → $12
function ticketPrice() {
// STEP 1: Use prompt() to ask "Enter your age"
// Store the result in a variable using let.
// STEP 2: Use parseInt() to convert the string to a whole number.
// Ages should be whole numbers, so use parseInt (not parseFloat).
// STEP 3: Check if the input is invalid.
// Invalid means: isNaN() is true OR the number is negative.
// If invalid, alert exactly: "Invalid input"
// Then return (exit the function early).
// STEP 4: Use if/else if/else to determine the ticket price.
// Check the age ranges in order:
//
// If age is 12 or less → alert exactly: "Child: $7"
// If age is 17 or less → alert exactly: "Teen: $12"
// If age is 64 or less → alert exactly: "Adult: $20"
// Otherwise → alert exactly: "Senior: $12"
//
// HINT: Since you already checked for negative numbers
// in STEP 3, you know the age is >= 0 by this point.
// So checking age <= 12 covers ages 0 through 12.
}