Skip to content

Commit

Permalink
Update treasure.js
Browse files Browse the repository at this point in the history
Added pirate soundbite.
Modified volume levels, and sound execution.
  • Loading branch information
DanCQ authored Jan 6, 2024
1 parent 1f27210 commit 9a86066
Showing 1 changed file with 36 additions and 7 deletions.
43 changes: 36 additions & 7 deletions treasure.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,19 @@ const box6 = document.getElementById("6");
const box7 = document.getElementById("7");
const box8 = document.getElementById("8");
const box9 = document.getElementById("9");
const lostTreasure = document.querySelector("h1");

const correct = document.getElementById("correct");
const wrong = document.getElementById("wrong");

const bonfire = new Audio("assets/bonfire.mp3"); //background music
bonfire.loop = true;
bonfire.volume = 0.6;

const ocean = new Audio("assets/ocean.mp3"); //ocean sounds
ocean.volume = 0.8;
const bonfire = new Audio("assets/bonfire.mp3"); //music
bonfire.loop = true;
bonfire.volume = 0.8;

const pirate = new Audio("assets/pirate.mp3");

let treasure = randomRange(1,9); //this is where the treasure is hidden

Expand All @@ -34,6 +39,12 @@ box7.onclick = function() { selection(7) };
box8.onclick = function() { selection(8) };
box9.onclick = function() { selection(9) };

lostTreasure.onclick = function() {
if(pirate.paused) {
pirate.play();
}
}


//Returns a random number within a chosen range
function randomRange(min, max) {
Expand All @@ -46,6 +57,7 @@ function randomRange(min, max) {
//compares the user's treasure selection to the randomly chosen selection
function selection(box) {

let arrg;
let lose = document.querySelector(".lose");
let win = document.querySelector(".win");

Expand All @@ -67,15 +79,15 @@ function selection(box) {

if (box == treasure) {

bonfire.volume = 0.4;
bonfire.volume = 0.3;
treasureChest.play(); //plays sound
win.style.visibility = "visible"; //shows message

score("win"); //updates score

setTimeout(function() {

bonfire.volume = 0.8;
bonfire.volume = 0.6;
win.style.visibility = "hidden";

}, 10000); //Gives time to celebrate, hides again
Expand All @@ -87,6 +99,22 @@ function selection(box) {
open.play(); //plays sound
lose.style.visibility = "visible"; //shows message

if(ocean.paused) {
ocean.play();

if(pirate.paused) {
arrg = randomRange(0,1); //won't play everytime

if(arrg == 1) {

setTimeout(function(){
pirate.play();
}, 600); //let's other sounds play first
}
}
}


setTimeout(function() {

score("lose");
Expand All @@ -103,6 +131,7 @@ function selection(box) {

window.onclick = function() {

ocean.play(); //plays ocean sounds
bonfire.play(); //plays music
if(bonfire.paused) {
bonfire.play(); //plays music
}
};

0 comments on commit 9a86066

Please sign in to comment.