vendredi 23 février 2018

Using an if function to start a song/video Javascript/HTML

bare with me. I'm somewhat new to this and I'm slowly but surely learning more and more. Right now I'm creating a simple and easy game based around golf. I want a certain song to start playing if the amount of points scored matches the amount of players. Then, the tally (not score) resets, so that it can occur again in the same game. So far, I've been able to create code that is able to alert the user when this occurs and reset the tally (again not the score). I also have code that plays the song every time the submit button is clicked and it works perfectly. However, when I try to use that music player function inside of the if statement that determines when to play the song and alert the user and reset the tally etc., the music does not play at all. Any help is greatly appreciated!!!!

here's the code for the player:

$(document).ready(function() {
$('#play-video').on('click', function(ev) {

$("#video")[0].src += "&autoplay=1";
ev.preventDefault();

});
});

here's the javascript code for the if function that I want it to perform inside of

    function Wow(){
var amountOfPlayers= document.getElementById("userInput").innerHTML;
if (tallyMark==amountOfPlayers){
alert("You Did It!");
tallyMark=0;
}
document.getElementById("tallies").innerHTML = tallyMark;

}

Here's the HTML code for the submit button (which runs many functions)

    <input id="play-video" href="#" type="submit" onClick="onClick(); scoreTally(); tally(); Wow();" value="Submit"></input>

And here's the HTML code for the video it's getting the song from:

   <iframe id="video" width="0" height="0" src="https://www.youtube.com/embed/QZXc39hT8t4?rel=0&amp;controls=0&amp;showinfo=0" ></iframe>

Aucun commentaire:

Enregistrer un commentaire