Basic Knowledge - Exercise 1
Question 1: Convert Seconds to Minutes and Seconds Completed
Return an array containing the whole minutes and remaining seconds for a non-negative integer number of seconds.
Expected output: [2,15] (print this with console.log)
function splitElapsedSeconds(seconds) {
// Write your solution here
}
console.log(splitElapsedSeconds(135));function splitElapsedSeconds(seconds) {
return [Math.floor(seconds / 60), seconds % 60];
}
console.log(splitElapsedSeconds(135));Question 2: Calculate a Rectangle Perimeter Completed
Return the perimeter of a rectangle from its width and height.
Expected output: 22 (print this with console.log)
function rectanglePerimeter(width, height) {
// Write your solution here
}
console.log(rectanglePerimeter(4, 7));function rectanglePerimeter(width, height) {
return 2 * (width + height);
}
console.log(rectanglePerimeter(4, 7));Question 3: Convert Kilometers to Meters Completed
Return the number of meters in the supplied distance in kilometers.
Expected output: 2500 (print this with console.log)
function kilometersToMeters(kilometers) {
// Write your solution here
}
console.log(kilometersToMeters(2.5));function kilometersToMeters(kilometers) {
return kilometers * 1000;
}
console.log(kilometersToMeters(2.5));Question 4: Calculate Change for Two Items Completed
Return the change after paying for both item prices with the given amount.
Expected output: 7 (print this with console.log)
function calculateCashChange(paid, firstPrice, secondPrice) {
// Write your solution here
}
console.log(calculateCashChange(20, 5, 8));function calculateCashChange(paid, firstPrice, secondPrice) {
return paid - firstPrice - secondPrice;
}
console.log(calculateCashChange(20, 5, 8));Question 5: Convert Celsius to Fahrenheit Completed
Convert the supplied Celsius temperature to Fahrenheit and return it.
Expected output: 68 (print this with console.log)
function celsiusToFahrenheit(celsius) {
// Write your solution here
}
console.log(celsiusToFahrenheit(20));function celsiusToFahrenheit(celsius) {
return celsius * 9 / 5 + 32;
}
console.log(celsiusToFahrenheit(20));Question 6: Count Complete Boxes Completed
Return the number of full boxes when items are packed into boxes of the given positive capacity.
Expected output: 4 (print this with console.log)
function countFullBoxes(items, capacity) {
// Write your solution here
}
console.log(countFullBoxes(23, 5));function countFullBoxes(items, capacity) {
return Math.floor(items / capacity);
}
console.log(countFullBoxes(23, 5));Question 7: Calculate a Trip's Total Distance Completed
Return the round-trip distance when the one-way distance is traveled a given number of times in each direction.
Expected output: 72 (print this with console.log)
function roundTripDistance(distance, trips) {
// Write your solution here
}
console.log(roundTripDistance(12, 3));function roundTripDistance(distance, trips) {
return distance * trips * 2;
}
console.log(roundTripDistance(12, 3));Question 8: Round Up Meeting Hours Completed
Return the minimum number of whole hours needed for the supplied non-negative number of minutes.
Expected output: 3 (print this with console.log)
function roundUpMeetingHours(minutes) {
// Write your solution here
}
console.log(roundUpMeetingHours(130));function roundUpMeetingHours(minutes) {
return Math.ceil(minutes / 60);
}
console.log(roundUpMeetingHours(130));Question 9: Calculate an Average Speed Completed
Return the distance divided by travel time. The time is greater than zero.
Expected output: 50 (print this with console.log)
function averageTravelSpeed(distance, hours) {
// Write your solution here
}
console.log(averageTravelSpeed(150, 3));function averageTravelSpeed(distance, hours) {
return distance / hours;
}
console.log(averageTravelSpeed(150, 3));Question 10: Find the Larger Reading Completed
Return the larger of two numeric readings. If they are equal, return either value.
Expected output: 24 (print this with console.log)
function largerSensorReading(first, second) {
// Write your solution here
}
console.log(largerSensorReading(17, 24));function largerSensorReading(first, second) {
return Math.max(first, second);
}
console.log(largerSensorReading(17, 24));