I am having issues with meeting the test cases for function getRandomLunch() and function showLunchMenu(). For some reason, it won’t accept the output for the test cases.
Here is my code:
const lunches = [];
function addLunchToEnd(arrVal, stringVal) {
arrVal.push(stringVal);
console.log(`${stringVal} added to the end of the lunch menu.`);
return arrVal;
}
function addLunchToStart(arrVal, stringVal) {
arrVal.unshift(stringVal);
console.log(`${stringVal} added to the start of the lunch menu.`);
return arrVal;
}
function removeLastLunch(arrVal) {
if (arrVal.length != 0) {
let removalItem = arrVal.pop();
console.log(`${removalItem} removed from the end of the lunch menu.`);
return arrVal;
}
console.log(“No lunches to remove.”);
return arrVal;
}
function removeFirstLunch(arrVal) {
if (arrVal.length != 0) {
let removalItem = arrVal.shift();
console.log(`${removalItem} removed from the start of the lunch menu.`);
return arrVal;
}
console.log(“No lunches to remove.”);
return arrVal;
}
function getRandomLunch(arrVal) {
if (arrVal.length != 0) {
const min = 0;
const max = arrVal.length - 1;
let randomVal = Math.floor(Math.random() * (max - min) + min);
console.log(`Randomly selected lunch: ${arrVal[randomVal]}`);
} else {
console.log("No lunches available.");
}
}
function showLunchMenu(arrVal) {
let […rest] = arrVal;
if (arrVal.length != 0) {
console.log(`Menu items: ${rest}`);
} else {
console.log("The menu is empty.");
}
}
// console.log(showLunchMenu([“Pizza”, “Burger”, “Fries”, “Salad”]));
Failed Test Cases:
24. When the input array is not empty, the function getRandomLunch should log a string in the format Randomly selected lunch: [Lunch Item] to the console.
29. showLunchMenu(["Greens", "Corns", "Beans"]) should log "Menu items: Greens, Corns, Beans" to the console.
30. showLunchMenu(["Pizza", "Burger", "Fries", "Salad"]) should log "Menu items: Pizza, Burger, Fries, Salad" to the console.