Calculator
Define 4 functions:
// Define the 4 functions here
function sum (x, y) {
return x + y;
}
function subtract(x,y) {
return x - y;
}
function multiply(x,y) {
return x * y;
}
function divide(x,y) {
return x / y;
}
Get number of characters, UPPER and lower
Define these 3 functions
// Define the 3 functions here
function getNumberOfChars(input) {
return input.length;
}
function getLower(input) {
return input.toLowerCase();
}
function getUpper(input) {
return input.toUpperCase();
}
Shopping List
You need to write the following function to make it work:
getMessage that takes 1 parameter and returns a string depending on the value of that parameter:
- When the number is below 0 (for example -1, -2, etc.), we want to show the message Invalid number
- When the number is 0, show the message: You don't have any items in your shopping list
- When the number is 1, show the message: You have one item in your shopping list
- When the number is above 1, show the message: You have more than 1 item in your shopping list
// Define the function here
function getMessage(input) {
if (input < 0) {
return "Invalid number"
}
if (input === 0) {
return "You don't have any items in your shopping list"
}
if (input === 1) {
return "You have one item in your shopping list"
}
if (input > 1) {
return "You have more than 1 item in your shopping list"
}
}