Conditional Statements - Exercise 2

Question 1: Label a Battery Level

Return "low" below 20, "medium" from 20 through 79, and "high" at 80 or above.

Expected output: "medium" (print this with console.log)

javascript

function batteryLevelLabel(level) {
  // Write your solution here
}

console.log(batteryLevelLabel(50));

Question 2: Choose a Parcel Category

Return "small" for weight up to 2, "medium" for weight up to 10, and "large" for greater weight.

Expected output: "medium" (print this with console.log)

javascript

function parcelWeightCategory(weight) {
  // Write your solution here
}

console.log(parcelWeightCategory(5));

Question 3: Classify a Temperature Alert

Return "freezing" below 0, "hot" above 35, and "normal" otherwise.

Expected output: "hot" (print this with console.log)

javascript

function temperatureAlertLabel(temperature) {
  // Write your solution here
}

console.log(temperatureAlertLabel(36));

Question 4: Label a Delivery Status

Return "arrived" for delivered, "on the way" for shipped, and "processing" for any other status.

Expected output: "on the way" (print this with console.log)

javascript

function deliveryStatusLabel(status) {
  // Write your solution here
}

console.log(deliveryStatusLabel("shipped"));

Question 5: Calculate a Parking Fee

Return 0 for up to 1 hour, 5 for more than 1 and up to 3 hours, and 10 for more than 3 hours. The input is non-negative.

Expected output: 5 (print this with console.log)

javascript

function parkingFeeForHours(hours) {
  // Write your solution here
}

console.log(parkingFeeForHours(2));

Question 6: Choose a Time Greeting

Return "morning" for hours below 12, "afternoon" for hours below 18, and "evening" otherwise. The hour is an integer from 0 to 23.

Expected output: "afternoon" (print this with console.log)

javascript

function daytimeGreetingLabel(hour) {
  // Write your solution here
}

console.log(daytimeGreetingLabel(13));

Question 7: Check a Password Length

Return "short" for fewer than 8 characters, "long" for more than 20, and "acceptable" otherwise.

Expected output: "short" (print this with console.log)

javascript

function passwordLengthLabel(password) {
  // Write your solution here
}

console.log(passwordLengthLabel("abc"));

Question 8: Choose a Transit Fare

Return 0 for ages under 5, 2 for ages 5 through 17, and 4 for ages 18 and over.

Expected output: 2 (print this with console.log)

javascript

function transitFareByAge(age) {
  // Write your solution here
}

console.log(transitFareByAge(10));

Question 9: Choose a Low Stock Action

Return "reorder" when quantity is below the minimum, "full" when it is above the maximum, and "ok" otherwise.

Expected output: "reorder" (print this with console.log)

javascript

function stockLevelAction(quantity, min, max) {
  // Write your solution here
}

console.log(stockLevelAction(2, 5, 20));

Question 10: Evaluate a Goal

Return "exceeded" when actual is greater than target, "met" when equal, and "not met" otherwise.

Expected output: "exceeded" (print this with console.log)

javascript

function evaluateGoal(actual, target) {
  // Write your solution here
}

console.log(evaluateGoal(12, 10));