Piano Player

why one kind of function works whether the other doesn’t?
This one works:

const colorChange = (note) => {
  note.onmousedown = function (event) {
    keyPlay(event);
  }
  note.onmouseup = function (event) {
    keyReturn(event);
  }
};

But the following one says ‘event’ is deprecated

let changeColor = function(note) {
  note.onmousedown = function() {
    keyPlay(event);
  }
  note.onmouseup = function() {
    keyReturn(event);
  }
};

I don’t really know anything but the basics of JS, so I could be wrong - but the issue with the second one is that event isn’t a function parameter, yet it’s passed as an argument.

2 Likes

I am beginner too no worries that’s why I am confused…
They both have ‘note’ as parameter and ‘event’ as an argument… Different ways of declaring a function shouldn’t be the reason (why VS Code) suggest differently.
Just try to put it in js file in VS Code to see…

The first one has event as a parameter for the function being used for note.onmouseup ,
the second does not.
(keyPlay has a keyReturn both have an argument event that has to come from somewhere.)

alternative

another way to do the same thing:

function changeColor(note) {
  note.onmousedown = keyPlay;
  note.onmouseup = keyReturn;
}
2 Likes

oh, I see!! I looked but didn’t see. I am so bad w those details… thank u very much

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.