Advertisement
makispaiktis

Codecademy - 25th Exercise (Piano Keys - JS)

Feb 29th, 2020 (edited)
579
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // The keys and notes variables store the piano keys
  2. const keys = ['c-key', 'd-key', 'e-key', 'f-key', 'g-key', 'a-key', 'b-key', 'high-c-key', 'c-sharp-key', 'd-sharp-key', 'f-sharp-key', 'g-sharp-key', 'a-sharp-key'];
  3. const notes = [];
  4. keys.forEach(function(key){
  5.   notes.push(document.getElementById(key));
  6. })
  7.  
  8. // Write named functions that change the color of the keys below
  9. function keyPlay(event){
  10.   event.target.style.backgroundColor = '#6df0c2';
  11. }
  12.  
  13. function keyReturn(event){
  14.   event.target.style.backgroundColor = '';
  15. }
  16. // Write a named function with event handler properties
  17. function eventAssignment(note){
  18.   note.onmousedown = function(){
  19.     keyPlay(event);
  20.   }
  21.   note.onmouseup = function(){
  22.     keyReturn(event);
  23.   }
  24. }
  25.  
  26. // Write a loop that runs the array elements through the function
  27. notes.forEach(eventAssignment);
  28.  
  29. // These variables store the buttons that progress the user through the lyrics
  30. let nextOne = document.getElementById('first-next-line');
  31. let nextTwo = document.getElementById('second-next-line');
  32. let nextThree = document.getElementById('third-next-line');
  33. let startOver = document.getElementById('fourth-next-line');
  34.  
  35. // This variable stores the '-END' lyric element
  36. let lastLyric = document.getElementById('column-optional');
  37.  
  38. // These statements are "hiding" all the progress buttons, but the first one
  39. nextTwo.hidden = true;
  40. nextThree.hidden = true;
  41. startOver.hidden= true;
  42.  
  43. // Write anonymous event handler property and function for the first progress button
  44. nextOne.onclick = function(){
  45.   nextTwo.hidden = false;
  46.   nextOne.hidden = true;
  47.   document.getElementById('letter-note-five').innerHTML = 'D';
  48.   document.getElementById('letter-note-six').innerHTML = 'C';
  49. }
  50.  
  51. // Write anonymous event handler property and function for the second progress button
  52. nextTwo.onclick = function(){
  53.   nextThree.hidden = false;
  54.   nextTwo.hidden = true;
  55.   document.getElementById('word-five').innerHTML = 'DEAR';
  56.   document.getElementById('word-six').innerHTML = 'FRI-';
  57.   lastLyric.style.display = 'inline-block';
  58.  
  59.   document.getElementById('letter-note-three').innerHTML = 'G';
  60.   document.getElementById('letter-note-four').innerHTML = 'E';
  61.   document.getElementById('letter-note-five').innerHTML = 'C';
  62.   document.getElementById('letter-note-six').innerHTML = 'B';
  63. }
  64.  
  65. // Write anonymous event handler property and function for the third progress button
  66. nextThree.onclick = function(){
  67.   startOver.hidden = false;
  68.   nextThree.hidden = true;
  69.   document.getElementById('word-one').innerHTML = 'HAP-';
  70.   document.getElementById('word-two').innerHTML = 'PY-';
  71.   document.getElementById('word-three').innerHTML = 'BIRTH';
  72.   document.getElementById('word-four').innerHTML = 'DAY';
  73.   document.getElementById('word-five').innerHTML = 'TO';
  74.   document.getElementById('word-six').innerHTML = 'YOU';
  75.  
  76.   document.getElementById('letter-note-one').innerHTML = 'F';
  77.   document.getElementById('letter-note-two').innerHTML = 'F';
  78.   document.getElementById('letter-note-three').innerHTML = 'E';
  79.   document.getElementById('letter-note-four').innerHTML = 'C';
  80.   document.getElementById('letter-note-five').innerHTML = 'D';
  81.   document.getElementById('letter-note-six').innerHTML = 'C';
  82.  
  83.   lastLyric.style.display = 'none';
  84. }
  85.  
  86. // This is the event handler property and function for the startOver button
  87. startOver.onclick = function() {
  88.   nextOne.hidden = false;
  89.   startOver.hidden = true;
  90.    document.getElementById('word-one').innerHTML = 'HAP-';
  91.   document.getElementById('letter-note-one').innerHTML = 'G';
  92.   document.getElementById('word-two').innerHTML = 'PY';
  93.   document.getElementById('letter-note-two').innerHTML = 'G';
  94.   document.getElementById('word-three').innerHTML = 'BIRTH-';
  95.   document.getElementById('letter-note-three').innerHTML = 'A';
  96.   document.getElementById('word-four').innerHTML = 'DAY';
  97.   document.getElementById('letter-note-four').innerHTML = 'G';
  98.   document.getElementById('word-five').innerHTML = 'TO';
  99.   document.getElementById('letter-note-five').innerHTML = 'C';
  100.   document.getElementById('word-six').innerHTML = 'YOU!';
  101.   document.getElementById('letter-note-six').innerHTML = 'B';
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement