<commit_before>window.onload = function(){
  // get all the drum keys
  var drumKeys = document.querySelectorAll('.key');

  // assign a transitionEnd event listener to each key to know when to remove playing class
  drumKeys.forEach((element) => element.addEventListener('transitionend', endOfTransitionHandler));

  // assign listener to set what happens when a key is pressed
  document.addEventListener("keydown", onPressHandler);

  // function runs when a key is pressed
  function onPressHandler(event){
    // get the key pressed and find the appropriate audio file
    var key = document.querySelector(`div[data-key="${event.keyCode}"]`),
        sound = document.querySelector(`audio[data-key="${event.keyCode}"]`);

    // reset the duration incase sound is already playing
    if(sound.duration > 0) sound.currentTime = 0;

    // add new class to animate pressed button
    key.classList.add('playing');

    // play the audiofile
    sound.play();
  }

  // function fires when css transition property ends
  function endOfTransitionHandler(event){
    // remove class playing to restore buttons to default style
    event.target.classList.remove('playing');
  }
};<commit_msg>add if statements to prevent errors<commit_after>window.onload = function(){
  // get all the drum keys
  var drumKeys = document.querySelectorAll('.key');

  // assign a transitionEnd event listener to each key to know when to remove playing class
  drumKeys.forEach((element) => element.addEventListener('transitionend', endOfTransitionHandler));

  // assign listener to set what happens when a key is pressed
  document.addEventListener("keydown", onPressHandler);

  // function runs when a key is pressed
  function onPressHandler(event){
    // get the key pressed and find the appropriate audio file
    var key = document.querySelector(`div[data-key="${event.keyCode}"]`),
        sound = document.querySelector(`audio[data-key="${event.keyCode}"]`);

    // reset the duration incase sound is already playing
    if(sound && sound.duration > 0) sound.currentTime = 0;

    // add new class to animate pressed button
    if(key) key.classList.add('playing');

    // play the audiofile
    if(sound) sound.play();
  }

  // function fires when css transition property ends
  function endOfTransitionHandler(event){
    // remove class playing to restore buttons to default style
    event.target.classList.remove('playing');
  }
};
{'fraction_non_alphanumeric': 0.10695187165775401, 'fraction_numerical': 0.0016454134101192926, 'mean_word_length': 3.8446215139442232, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2246815', 'n_tokens_mistral': 628, 'n_tokens_neox': 617, 'n_words': 224}