Operators - Exercise 1
Question 1: Add Basket Prices Completed
Return the sum of two item prices.
Expected output: 20 (print this with console.log)
function addBasketPrices(first, second) {
// Write your solution here
}
console.log(addBasketPrices(12, 8));function addBasketPrices(first, second) {
return first + second;
}
console.log(addBasketPrices(12, 8));Question 2: Calculate Remaining Credit Completed
Return the starting credit minus the amount spent.
Expected output: 32 (print this with console.log)
function remainingCredit(credit, spent) {
// Write your solution here
}
console.log(remainingCredit(50, 18));function remainingCredit(credit, spent) {
return credit - spent;
}
console.log(remainingCredit(50, 18));Question 3: Price Identical Tickets Completed
Return the price of one ticket multiplied by the number of tickets.
Expected output: 28 (print this with console.log)
function priceTickets(price, quantity) {
// Write your solution here
}
console.log(priceTickets(7, 4));function priceTickets(price, quantity) {
return price * quantity;
}
console.log(priceTickets(7, 4));Question 4: Share an Expense Completed
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)
function shareExpense(bill, people) {
// Write your solution here
}
console.log(shareExpense(84, 4));function shareExpense(bill, people) {
return bill / people;
}
console.log(shareExpense(84, 4));Question 5: Find Leftover Seats Completed
Return the remainder after dividing seats into equal groups. The group size is greater than zero.
Expected output: 3 (print this with console.log)
function leftoverSeats(seats, groupSize) {
// Write your solution here
}
console.log(leftoverSeats(23, 5));function leftoverSeats(seats, groupSize) {
return seats % groupSize;
}
console.log(leftoverSeats(23, 5));Question 6: Square a Grid Side Completed
Use the exponentiation operator to return the area of a square from its side length.
Expected output: 36 (print this with console.log)
function squareGridSide(side) {
// Write your solution here
}
console.log(squareGridSide(6));function squareGridSide(side) {
return side ** 2;
}
console.log(squareGridSide(6));Question 7: Increase Stored Points Completed
Use += to add earned points to the starting total and return it.
Expected output: 20 (print this with console.log)
function increaseStoredPoints(total, earned) {
// Write your solution here
}
console.log(increaseStoredPoints(14, 6));function increaseStoredPoints(total, earned) {
total += earned;
return total;
}
console.log(increaseStoredPoints(14, 6));Question 8: Apply a Percentage Discount Completed
Return the price after subtracting the given whole-number discount percentage.
Expected output: 60 (print this with console.log)
function applyPercentageDiscount(price, percent) {
// Write your solution here
}
console.log(applyPercentageDiscount(80, 25));function applyPercentageDiscount(price, percent) {
return price * (1 - percent / 100);
}
console.log(applyPercentageDiscount(80, 25));Question 9: Compare Delivery Distances Completed
Return true if the first distance is strictly shorter than the second.
Expected output: true (print this with console.log)
function isShorterDelivery(first, second) {
// Write your solution here
}
console.log(isShorterDelivery(4, 9));function isShorterDelivery(first, second) {
return first < second;
}
console.log(isShorterDelivery(4, 9));Question 10: Check Exact Access Code Completed
Return whether two supplied access codes are strictly equal, without type conversion.
Expected output: false (print this with console.log)
function matchesExactAccessCode(entered, stored) {
// Write your solution here
}
console.log(matchesExactAccessCode("42", 42));function matchesExactAccessCode(entered, stored) {
return entered === stored;
}
console.log(matchesExactAccessCode("42", 42));