-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
30 lines (25 loc) · 2.04 KB
/
script.js
File metadata and controls
30 lines (25 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
madlibBase = ['Last night I dreamed I was a adj butterfly with blue splotches that looked like blueberries. I flew to place with my best friend, cartoon, who was a adj noun. We ate some popcorn when we got there and then decided to verb. The dream ended when I said, "all\'s well that ends well"',
'Today I met the Queen of place during a quick trip to place. I had left the house because I really needed to pick up a dozen adj noun in order to repair my noun. I wasn\'t planning on meeting her or I probably wouldn\'t have been so adj! I know most people would have bowed, but I forgot and decided to verb adv instead. She smiled politely and then said, "Better Luck Next Time!"',
'Say noun, the photographer adv said as the camera flashed! cartoon and I had gone to place to get our photos taken today. The first photo we really wanted was a picture of us dressed as noun pretending to be a noun. When we saw the proofs of it, I was a bit adj because it looked different than in my head. (I hadnt imagined a noun behind us.) However, the second photo was exactly what I wanted. We both looked like we were ready to verb --exactly what I had in mind!'];
const dictionary = {
adjLib: [ 'happy', 'beautiful', 'sad', 'precocious', 'ugly'],
verbLib: [ 'jump', 'eat', 'think', 'code', 'exaggerate'],
nounLib: [ 'car', 'squirrel', 'man', 'woman', 'sun'],
advLib: ['quickly', 'sneakily', 'seductively', 'arrogantly', 'jauntily'],
placeLib: [ 'Nashville', 'school', 'barbershop', 'moon', 'Washington DC'],
cartoonLib: [ 'Yogi Bear', 'Fred Flintstone', 'Pikachu', 'Goku', 'Johnny Bravo']
}
const madlibgen = () => {
let madlibResult = madlibBase[randNum(madlibBase.length)]
for (const key in dictionary) {
while (madlibResult.includes(key.slice(0, -3))){
madlibResult = madlibResult.replace(key.slice(0, -3), genRandElement(dictionary[key]))
}
}
return madlibResult;
}
const randNum = num => {
return Math.floor(Math.random() * num)
};
const genRandElement = array => array[randNum(array.length)]
console.log(madlibgen());