-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscripts.js
63 lines (52 loc) · 1.58 KB
/
scripts.js
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
const badCoffee = 'Pine Bark';
const brands = [
{"Foldgers": 10},
{"Hardees": 0},
{"Petes": 75},
{"Starbucks": 60},
{"Stumptown": 80},
{"Deathwish": 2000},
{"Water Avenue": 100}
];
function isGood(grinds){
return (grinds > 70) ? true : false;
}
function coffee(pour = 'Deathwish'){
let brew;
let cup = pour.replace(/[\W_-]/g, '').toLowerCase().trim();
console.log(cup);
const brand = Object.keys(brands);
const taste = Object.values(brands);
for(let grind = 0; grind < brands.length; grind += 1){
const name = Object.keys(taste[grind])[0].replace(/[\W_-]/g, '').toLowerCase().trim();
const rating = Object.values(taste[grind]);
if(cup && cup.includes(name)){
brew = isGood(parseInt(rating));
}
}
pour = pour.trim()
return (brew) ? `Drink ${pour} Now!` : `Uuuuggg, ${badCoffee}! ${pour}, Toss-it!`;
}
document.addEventListener('DOMContentLoaded', () => {
const toDrink = document.querySelector('.coffee');
const whatBrand = document.querySelector('.cup-a-joe');
const event = new Event('change');
whatBrand.addEventListener('change', (e) => {
toDrink.innerHTML = "";
toDrink.appendChild(document.createTextNode(coffee(e.target.value)));
});
whatBrand.value = "Deathwish";
whatBrand.dispatchEvent(event);
setTimeout(()=>{
whatBrand.value = "Foldgers";
whatBrand.dispatchEvent(event);
}, 15000);
setTimeout(()=>{
whatBrand.value = "Starbucks";
whatBrand.dispatchEvent(event);
}, 20000);
setTimeout(()=>{
whatBrand.value = "Stumptown";
whatBrand.dispatchEvent(event);
}, 25000);
});