-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
43 lines (34 loc) · 1.07 KB
/
script.js
File metadata and controls
43 lines (34 loc) · 1.07 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
31
32
33
34
35
36
37
38
39
40
41
42
43
// apiUrl = "https://opentdb.com/api.php?amount=10&category=18&type=boolean"
// function processResponse(response){
// console.log("prossesing the response with a staus of" ,response.status)
// if(response.ok){
// return response.json()
// }
// else{
// throw new Error("http error:", response.status)
// }
// }
// function displayQuizData(data){
// console.log(data)
// }
// function handleError(error){
// console.error("error fetching data", error)
// }
// fetch(apiUrl)
// .then(processResponse)
// .then(displayQuizData)
// .catch(handleError)
const categoriesList = document.getElementById("categories-list")
fetch("https://opentdb.com/api_category.php")
.then(response=>response.json())
.then(data=>{
const categories = data.trivia_categories
categories.forEach(category =>{
const li = document.createElement("li")
li.textContent = `${category.id}: ${category.name}`
categoriesList.appendChild(li)
})
})
.catch (error=> {
console.error("error fetching categories:", error)
})