audio onclick play code example
Example 1: javascript play sound onclick
var audio = new Audio("soundfile.wav");
document.onclick = function() {
audio.play();
}
Example 2: in if condition how to set alert music in javascript
if (x > 10) {
var snd = new Audio('/alarm.mp3');
snd.play();
alert("Thank you!");
}