// The keys and notes variables store the piano keys
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'];
const notes = [];
keys.forEach(function(key){
notes.push(document.getElementById(key));
})
// Write named functions that change the color of the keys below
const keyPlay = function(event){
event.target.style.backgroundColor = "#ababab";
}
const keyReturn = function(event){
event.target.style.backgroundColor = "";
}
// Write a named function with event handler properties
function eventAssignment(note){
note.onmousedown = keyPlay;
note.onmouseup = function(){
keyReturn(event);
}
}
// Write a loop that runs the array elements through the function
notes.forEach(eventAssignment);
LINE-17 и LINE-18 служат схожим целям, поскольку хорошо запускают обработчики событий, инструктор говорит мне не использовать этот синтаксис в LINE-17, даже если он работает нормально. он как бы упоминает кое-что, что полностью у меня в голове: «мы не можем определить note.onmousedown
для функции keyPlay
, поскольку это просто переопределит функцию (я не знаю, какую функцию он называет переопределенной)»
Любая помощь приветствуется.