Piano Keys tasks 4-5

I don’t understand why we can’t simply assign function keyPlay to trigger note.onmousedown like this:

note.onmousedown = keyPlay(event);

Why it doesn’t work?

1 Like

I can’t understand it too!

The above line invokes the function before assignment. We don’t want the function to run at this point, so assign only a callback reference…

note.onmousedown = keyPlay;
1 Like