Skip to content

Instantly share code, notes, and snippets.

@claraj
Created April 26, 2024 17:28
Show Gist options
  • Save claraj/d6e01ca13191f7c38e861850a22ba75b to your computer and use it in GitHub Desktop.
Save claraj/d6e01ca13191f7c38e861850a22ba75b to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<p>Here's a random yes or no: <span id="yes-no"></span></p>
<script>
let yesNo = document.querySelector('#yes-no')
console.log('Script starting!')
fetch('https://yesno.wtf/api').then( response => {
console.log('Received response!')
return response.json()
}).then( json => {
console.log('Have the JSON data!')
yesNo.innerHTML = json.answer
})
console.log('This is coded after the fetch, but when do you see this message?')
/* Yes/No API returns yes or no response at random, and a GIF representing yes or no.
An example response is
{
"answer": "yes",
"forced": false,
"image": "https://yesno.wtf/assets/yes/12-e4f57c8f172c51fdd983c2837349f853.gif"
}
*/
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment