-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
52 lines (40 loc) · 1.45 KB
/
script.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
import * as restModule from './restaurantList.js';
// Main pop up div
let restuarantPopUp = document.querySelector('.restaurantBox');
// Restaurant categories
let categoryBtns = document.querySelectorAll('.category');
categoryBtns.forEach((choice)=>{
choice.addEventListener('click',()=>{
let finalCategory;
if(choice.id === 'anything'){
finalCategory = Object.keys(restModule.restaurantList);
} else{
finalCategory = Object.keys(restModule.restaurantList).filter((rest)=>{
if(restModule.restaurantList[rest].categoryArr.includes(choice.id)){
return true;
}
});
}
let randomRest = finalCategory[Math.floor(Math.random()*Math.floor(finalCategory.length))];
restModule.restaurantList[randomRest].display(
restuarantPopUp,
document.getElementById('restName'),
document.getElementById('restNumber'),
)
});
});
// Page reset button
let retryBtn = document.querySelector('.retry');
retryBtn.addEventListener('click',()=>{
location.reload();
});
// About button
let aboutBtn = document.getElementById('about');
let aboutExit = document.getElementById('aboutExit');
let aboutBox = document.getElementById('aboutBox');
aboutBtn.addEventListener('click',()=>{
aboutBox.style.display = 'block';
});
aboutExit.addEventListener('click',()=>{
aboutBox.style.display = 'none';
});