-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript.js
28 lines (24 loc) · 1008 Bytes
/
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
const inspireBtn = document.getElementById("inspireBtn")
const anotherBtn = document.getElementById("anotherBtn")
const descriptionEl = document.getElementById("description")
const ideaTextEl = document.getElementById("ideaText")
const apiUrl = "https://corsproxy.io/?https://itsthisforthat.com/api.php?json"
inspireBtn.addEventListener("click", getIdea)
anotherBtn.addEventListener("click", getIdea)
function getIdea() {
descriptionEl.style.display = "none"
inspireBtn.style.display = "none"
anotherBtn.style.display = "block"
fetch(apiUrl)
.then((response) => response.json())
.then((data) => {
const { this: thisValue, that: thatValue } = data
ideaTextEl.textContent = `You should make a ${thisValue} that will be used for ${thatValue}.`
})
.catch((error) => {
console.error("Error:", error)
ideaTextEl.textContent =
"Sorry, something went wrong. Please try again later."
throw new Error("Error while creating your Idea:", error)
})
}