Conditional Statements - Exercise 1

Question 1: Choose a Rain Plan

Return "umbrella" if it is raining, otherwise "no umbrella". The argument is a boolean.

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

javascript

function chooseRainPlan(isRaining) {
  // Write your solution here
}

console.log(chooseRainPlan(true));

Question 2: Check a Library Loan Limit

Return true if the number of borrowed books is below the limit.

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

javascript

function canBorrowAnotherBook(borrowed, limit) {
  // Write your solution here
}

console.log(canBorrowAnotherBook(3, 5));

Question 3: Choose a Jacket

Return "jacket" when the temperature is below 15 and "no jacket" otherwise.

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

javascript

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

console.log(chooseTemperatureClothing(12));

Question 4: Check a Booking Window

Return true if daysUntilDeparture is between 1 and 30 inclusive.

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

javascript

function isBookingWindowOpen(daysUntilDeparture) {
  // Write your solution here
}

console.log(isBookingWindowOpen(10));

Question 5: Choose a Page Size

Return the supplied positive page size, or 10 when it is zero or negative.

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

javascript

function choosePositivePageSize(size) {
  // Write your solution here
}

console.log(choosePositivePageSize(-1));

Question 6: Clamp a Brightness Value

Return the input clamped to the inclusive range 0 to 100.

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

javascript

function clampBrightness(brightness) {
  // Write your solution here
}

console.log(clampBrightness(120));

Question 7: Check a File Extension

Return true if the case-sensitive filename ends with ".js".

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

javascript

function hasJavaScriptExtension(filename) {
  // Write your solution here
}

console.log(hasJavaScriptExtension("app.js"));

Question 8: Choose a Queue Direction

Return "wait" if peopleAhead is greater than zero and "your turn" otherwise.

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

javascript

function chooseQueueMessage(peopleAhead) {
  // Write your solution here
}

console.log(chooseQueueMessage(2));

Question 9: Calculate a Member Price

Return the price minus the supplied discount for members; otherwise return the full price. isMember is a boolean.

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

javascript

function priceForMember(price, discount, isMember) {
  // Write your solution here
}

console.log(priceForMember(30, 5, true));

Question 10: Check a Nonempty Playlist

Return true when the supplied array contains at least one track.

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

javascript

function playlistHasTracks(tracks) {
  // Write your solution here
}

console.log(playlistHasTracks(["song"]));