Skip to content

Commit 39a17dc

Browse files
committed
added lunchPuzzes.js
1 parent 7823721 commit 39a17dc

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

JS_Bits/lunchPuzzles.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
const lunches = [];
2+
3+
function addLunchToEnd(arr, str) {
4+
arr.push(str);
5+
console.log(`${str} added to the end of the lunch menu.`);
6+
return arr;
7+
}
8+
9+
function addLunchToStart(arr, str) {
10+
arr.unshift(str);
11+
console.log(`${str} added to the start of the lunch menu.`);
12+
return arr;
13+
}
14+
15+
function removeLastLunch(arr) {
16+
if (arr.length === 0) {
17+
console.log(`No lunches to remove.`);
18+
} else {
19+
let str = arr.pop();
20+
console.log(`${str} removed from the end of the lunch menu.`);
21+
}
22+
return arr;
23+
}
24+
25+
function removeFirstLunch(arr) {
26+
if (arr.length === 0) {
27+
console.log(`No lunches to remove.`);
28+
} else {
29+
let str = arr.shift();
30+
console.log(`${str} removed from the start of the lunch menu.`);
31+
}
32+
return arr;
33+
}
34+
35+
function getRandomLunch(arr) {
36+
let arrSize = arr.length;
37+
let randomInt = Math.floor(Math.random() * (arrSize));
38+
if (arr.length === 0) {
39+
console.log(`No lunches available.`)
40+
} else {
41+
console.log(`Randomly selected lunch: ${arr[randomInt]}`);
42+
}
43+
}
44+
45+
function showLunchMenu(arr) {
46+
if (arr.length === 0) {
47+
console.log(`The menu is empty.`)
48+
} else {
49+
console.log(`Menu items: ${arr.join(', ')}`);
50+
}
51+
}
52+

0 commit comments

Comments
 (0)