Hi!
I’m currently on the Piano Keys project inside the section 6 “Building Interactive JS Websites” of the web development path (https://www.codecademy.com/paths/web-development/tracks/build-interactive-websites/modules/dom-javascript-events/projects/piano-keys).
From step 2 to 5, it is asked to write:
// Write named functions that change the color of the keys below
const keyPlay = function (event) {
event.target.style.backgroundColor = "blue";
};
const keyReturn = function (event) {
event.target.style.backgroundColor = "";
};
// Write a named function with event handler properties
const eventAssignment = function (note) {
note.onmousedown = function () {
keyPlay(event);
};
note.onmouseup = function () {
keyReturn(event);
};
};
Why are the KeyPkay and KeyReturn declarations needed, instead of just writing their contents inside the event handler functions associated with the note.onmouseXX events (as these functions are just used once inside the onmouseXX events) ?
Thanks a lot,
Victor