<commit_before>// Adding an Event Listener
// The name of the function (without the "()") is passed to the event listener
// Adding the event listener to all button (with class drum)
for (var i = 0; i < document.querySelectorAll(".drum").length; i++) {
  document.querySelectorAll(".drum")[i].addEventListener("click", function() {
    // Switching based on the letter inside the inner HTML of each button
    var buttonInnerHTML = this.innerHTML;
    switch (buttonInnerHTML) {
      case "w":
        var tom1 = new Audio("sounds/tom-1.mp3");
        tom1.play();
        break;

      case "a":
        var tom2 = new Audio("sounds/tom-2.mp3");
        tom2.play();
        break;

      case "s":
        var tom3 = new Audio("sounds/tom-3.mp3");
        tom3.play();
        break;

      case "d":
        var tom4 = new Audio("sounds/tom-4.mp3");
        tom4.play();
        break;

      case "j":
        var snare = new Audio("sounds/snare.mp3");
        snare.play();
        break;

      case "k":
        var crash = new Audio("sounds/crash.mp3");
        crash.play();
        break;

      case "l":
        var kick = new Audio("sounds/kick-bass.mp3");
        kick.play();
        break;
      default:
        console.log(buttonInnerHTML);
    }
  });
}
<commit_msg>Adding a keyboard event listener to the page and re-organizing the code.<commit_after>// Adding an Event Listener
// The name of the function (without the "()") is passed to the event listener
// Adding the event listener to all buttons (with class drum, for the mouse) 
for (var i = 0; i < document.querySelectorAll(".drum").length; i++) {
  document.querySelectorAll(".drum")[i].addEventListener("click", function() {
    // Switching based on the letter inside the inner HTML of each button
    var buttonInnerHTML = this.innerHTML;
    playSound(buttonInnerHTML);
  });
}

// Adding a keypress event Listener to the whole page
document.addEventListener("keypress", function(event){
  var key = event.key;
  console.log(key);
  playSound(key);
});

// Playing the relevant sound
function playSound(key){
  switch (key) {
    case "w":
      var tom1 = new Audio("sounds/tom-1.mp3");
      tom1.play();
      break;

    case "a":
      var tom2 = new Audio("sounds/tom-2.mp3");
      tom2.play();
      break;

    case "s":
      var tom3 = new Audio("sounds/tom-3.mp3");
      tom3.play();
      break;

    case "d":
      var tom4 = new Audio("sounds/tom-4.mp3");
      tom4.play();
      break;

    case "j":
      var snare = new Audio("sounds/snare.mp3");
      snare.play();
      break;

    case "k":
      var crash = new Audio("sounds/crash.mp3");
      crash.play();
      break;

    case "l":
      var kick = new Audio("sounds/kick-bass.mp3");
      kick.play();
      break;
    default:
      console.log(key);
    }
}

{'fraction_non_alphanumeric': 0.14255394411036434, 'fraction_numerical': 0.014149274849663955, 'mean_word_length': 2.3231492361927146, 'pattern_counts': {'":': 14, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5634666', 'n_tokens_mistral': 908, 'n_tokens_neox': 890, 'n_words': 261}