Operators - Exercise 1

Question 1: Add Basket Prices

Return the sum of two item prices.

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

javascript

function addBasketPrices(first, second) {
  // Write your solution here
}

console.log(addBasketPrices(12, 8));

Question 2: Calculate Remaining Credit

Return the starting credit minus the amount spent.

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

javascript

function remainingCredit(credit, spent) {
  // Write your solution here
}

console.log(remainingCredit(50, 18));

Question 3: Price Identical Tickets

Return the price of one ticket multiplied by the number of tickets.

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

javascript

function priceTickets(price, quantity) {
  // Write your solution here
}

console.log(priceTickets(7, 4));

Question 4: Share an Expense

Divide the bill equally by the number of people. The number of people is greater than zero.

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

javascript

function shareExpense(bill, people) {
  // Write your solution here
}

console.log(shareExpense(84, 4));

Question 5: Find Leftover Seats

Return the remainder after dividing seats into equal groups. The group size is greater than zero.

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

javascript

function leftoverSeats(seats, groupSize) {
  // Write your solution here
}

console.log(leftoverSeats(23, 5));

Question 6: Square a Grid Side

Use the exponentiation operator to return the area of a square from its side length.

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

javascript

function squareGridSide(side) {
  // Write your solution here
}

console.log(squareGridSide(6));

Question 7: Increase Stored Points

Use += to add earned points to the starting total and return it.

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

javascript

function increaseStoredPoints(total, earned) {
  // Write your solution here
}

console.log(increaseStoredPoints(14, 6));

Question 8: Apply a Percentage Discount

Return the price after subtracting the given whole-number discount percentage.

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

javascript

function applyPercentageDiscount(price, percent) {
  // Write your solution here
}

console.log(applyPercentageDiscount(80, 25));

Question 9: Compare Delivery Distances

Return true if the first distance is strictly shorter than the second.

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

javascript

function isShorterDelivery(first, second) {
  // Write your solution here
}

console.log(isShorterDelivery(4, 9));

Question 10: Check Exact Access Code

Return whether two supplied access codes are strictly equal, without type conversion.

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

javascript

function matchesExactAccessCode(entered, stored) {
  // Write your solution here
}

console.log(matchesExactAccessCode("42", 42));