-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
43 lines (36 loc) · 1.56 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
const searchBtn = document.querySelector("#app__search").addEventListener("click", findActivity);
// Getting the dropdown menu items start
const typeItems = Array.from(document.querySelectorAll(".select-type__item"));
const selectTypeText = document.querySelector("#select-type__title h2");
// Getting the dropdown menu items finish
// Put the chosen type of activity in the drowdown title
typeItems.forEach((choice) => {
choice.addEventListener("click", chooseItem);
});
function chooseItem(item) {
const selectTypeText = document.querySelector("#select-type__title h2");
selectTypeText.innerText = item.target.innerText;
typeList.classList.toggle("select--show");
}
function findActivity() {
const chosenItem = selectTypeText.innerText.toLowerCase();
console.log(chosenItem);
fetch(`http://www.boredapi.com/api/activity?type=${chosenItem}`)
.then((data) => data.json())
.then((data) => {
const searchResult = document.querySelector("#app__result");
searchResult.textContent = data.activity;
})
.catch(() => {
console.log("error");
});
}
const selectTypeBtn = document.querySelector("#select-type__title");
const typeList = document.querySelector("#select-type__options");
// Open select dropdown menu
selectTypeBtn.addEventListener("click", () => {
typeList.classList.toggle("select--show");
console.log(typeList.classList.contains("select--show"));
const selectArrow = document.querySelector("#select-type__title i");
selectArrow.classList.toggle("arrow-rotate");
});