Skip to main content
All Questions

Build a piano keys widget that responds to mouse and keyboard input.

Unlock detailed company stats for this questionUpgrade

Stack: vanilla HTML, CSS and JavaScript, no frameworks or libraries. You are given a row of six piano keys: C, D, E, F, G, A. A key should appear pressed the entire time it is held down and return to normal the instant it is released. 'Pressed' means the element has the CSS class active (the styling for .key.active is already written). Keys must respond to both mouse (press and hold on a key) and the physical keyboard (press and hold the matching letter: c, d, e, f, g, a).

Requirements:

  1. Holding the mouse down on a key adds active; releasing removes it.
  2. Holding the corresponding letter on the physical keyboard adds active; releasing removes it.
  3. Multiple keys can be active at once; holding c and e together lights up both.
  4. Keys not in the set (e.g. k, Enter, arrow keys) are ignored.

Format · Technical screening.

Community answers

No answers contributed by the community yet.

Related courses

Course

Software Engineering Interview Prep

Land your dream software engineering role at Google, Amazon, Microsoft, Meta, Apple, and other top companies. Learn from mock interviews, frameworks, and advice from senior candidates—practice data structures, algorithms, system design, people management, behavioral interviews, and more.

Course

System Design Interviews

Learn how to answer the latest system design questions across product, infrastructure, and AI domains. Features in-depth video examples, written breakdowns, and helpful reference patterns. Watch senior engineers and managers answer these questions in mock interview videos.