Created
March 30, 2022 16:44
-
-
Save JeremiJohnson/d2bd00aa8f1a79fc0683a76c9744a3b8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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