Tell us what’s happening:
I am logging everything to the console that I should be and I dont understand why its not passing numbers 13, 18, 23, 29 and 30
Your code so far
let lunches = []
const addLunchToEnd = (arr, str) => {
arr.push(str)
console.log(`${str} added to the end of the lunch menu.`)
return arr
}
console.log(addLunchToEnd(lunches, 'Tacos'))
console.log(addLunchToEnd(lunches, 'Burger'))
console.log(addLunchToEnd(lunches, 'Pizza'))
console.log(addLunchToEnd(lunches, 'Salmon'))
console.log(addLunchToEnd(lunches, 'Fish and Chips'))
console.log(addLunchToEnd(lunches, 'Chicken'))
console.log(addLunchToEnd(lunches, 'Hot Dogs'))
console.log(lunches)
const addLunchToStart = (arr, str) => {
arr.unshift(str)
console.log(`${str} added to the start of the lunch menu.`)
return arr
}
console.log(addLunchToStart(lunches, 'Sushi'))
console.log(lunches)
const removeLastLunch = (arr) => {
if (arr.length == 0){
console.log('No lunches to remove.')
} else {let pop = arr.pop()
console.log(`${pop} removed from the end of the lunch menu`)}
return arr
}
console.log(removeLastLunch(lunches))
console.log(removeLastLunch(['Stew', 'Soup', 'Toast']))
const removeFirstLunch = (arr) => {
if (arr.length == 0){
console.log('No lunches to remove.')
} else {let shift = arr.shift()
console.log(`${shift} removed from the start of the lunch menu`)}
return arr
}
console.log(removeFirstLunch(lunches))
const getRandomLunch = (arr) => {
if (arr.length == 0){
console.log('The menu is empty')
} else {
let randNum = Math.round(Math.random() * arr.length)
let rand = arr[randNum]
console.log(`Randomly selected lunch: ${rand}`)
}
return arr
}
console.log(getRandomLunch(lunches))
const showLunchMenu = (arr) => {
if (arr.length == 0) {
console.log('The menu is empty.')
} else {
let list = arr.join(', ')
return `Menu items: ${list}`
}
}
console.log(showLunchMenu(lunches))
console.log(showLunchMenu(["Pizza", "Burger", "Fries", "Salad"]))
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36
Challenge Information:
Build a Lunch Picker Program - Build a Lunch Picker Program