JSFiddle - React, Tailwind, and code Playground

by alvarotrigo

HTML

Click here first.
<br><br> Now, type any letter


<img src="https://media.giphy.com/media/pVe8bu4l12iT6/giphy.gif" />

JavaScript

var sound = new Audio('https://www.w3schools.com/html/horse.mp3');

document.addEventListener('keydown', playSound);


function playSound() {
  console.log("va");
  //in order to play the same sound over itself
  //in order to play the same sound over itself
  var promise = sound.cloneNode(true).play();

  //we just dont want to show the console error when autoplay is disabled :)
  if (typeof promise !== undefined) {
    promise.then(function() {
      // Autoplay started!
    }).catch(function(error) {
      //error
    });
  }

}