document.getElementById('window-container').addEventListener("click", function () {
fetch("https://v2.jokeapi.dev/joke/Christmas")
.then(response => {
if (!response.ok) {
throw new Error("Oops, try again!");
}
return response.json();
})
.then(data => {
jokeQuestion.innerText = `Q: ${data.setup}` //"setup" is a property of the API
jokeAnswer.innerText = `A: ${data.delivery}` //"delivery" is a property of the API
})
.catch(error => {
console.error('Error:', error);
});
document.querySelector('.left-door').style = "animation: left-open 0.3s forwards"
document.querySelector('.right-door').style = "animation: right-open 0.3s forwards"
document.querySelector('.joke-display').style = "animation: display-joke 0.3s forwards"
})
/** uncomment one of these **/
// import OpenAI from "openai" --> no
// import { HfInference } from '@huggingface/inference' --> no
/**
* 🎄 Challenge:
* 1. When clicked, the doors should open
* to reveal a festive joke.
* 🎁 hint.md for help!
**/
/*
API I ended up using: https://sahithyandev.github.io/sv443-joke-api-js-wrapper/
*/
let jokeQuestion = document.getElementById("joke-question")
let jokeAnswer = document.getElementById("joke-answer")