-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
23 lines (22 loc) · 826 Bytes
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
document.addEventListener("DOMContentLoaded", function() {
document.getElementById("joke-btn").addEventListener("click", function() {
fetchJoke();
});
});
function fetchJoke() {
fetch("https://icanhazdadjoke.com/", { // Random API I found. You can replace and configurate this to a different API.
headers: {
'Accept': 'application/json'
}
})
.then(response => response.json())
.then(data => {
document.getElementById("output-p").textContent = data.joke;
console.log("Success! Yey")
document.getElementById("joke-btn").textContent = "Generate again"
})
.catch(error => {
console.error("Error fetching data:", error); // Check the console for errors
document.getElementById("output-p").textContent = "Error fetching data.";
});
}