Skip to content

Instantly share code, notes, and snippets.

@JeremiJohnson
Created March 30, 2022 16:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save JeremiJohnson/d2bd00aa8f1a79fc0683a76c9744a3b8 to your computer and use it in GitHub Desktop.
Save JeremiJohnson/d2bd00aa8f1a79fc0683a76c9744a3b8 to your computer and use it in GitHub Desktop.
let button = document.querySelector("button");
let answer = document.querySelector("#answer");
document.addEventListener("DOMContentLoaded", () => {
fetch('db/jsproject.json')
.then(response => response.json())
.then(answers => {
button.addEventListener("click", () => {
const index = [Math.floor(Math.random() * answers.length)]
console.log(answers[index])
answer.innerHTML = answers[index]
})
})
})
let a1 = document.getElementById("flora");
let a2 = document.getElementById("vacuum");
let a3 = document.getElementById("time");
let x;
const audioSources = ["vid/1.wav", "audio/2.wav", "audio/3.wav"];
const player = document.getElementById("player");
function playAudio() {
let audioSource = audioSources[Math.floor(Math.random() * audioSources.length)];
player.src = audioSource;
};
player.addEventListener('ended', playAudio);
playAudio(); // start audio playing immediately
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment