• the problem is, whenever I press/release the button, the piezo speaker
    beeps until the LEDs are cleared

    That's what you program is supposed to do. There is no multitasking in Javascript, just a single thread. As such, the timer to stop the beep expires while your WHILE loop is running, but the code to stop the beep only gets executed when the CPU is idle. That's the case when the function containing the WHILE loop is finished. (There might be better and technical more accurate explanations.)

    In case you need to write

    display(1, hourFirstDigit);
        display(2, hourSecondDigit);
    

    repeatedly then do this using a function. Start the function with var yolo=setInterval(...) and stop it with clearInterval(yolo). Don't use WHILE or FOR in such cases.

    Regarding

    pretty simple, right?

    No, it's not simple. You need two function while one function with 3 lines would do.

About

Avatar for maze1980 @maze1980 started