javascriptkhan-academy

Javascript programming on Khanacademy. How come the buttons on the bottom half does not work?


I am working on a calculator but after setting up the buttons the bottom half of the buttons does not react like the top half. Please help.

Link to project: https://www.khanacademy.org/computer-programming/calculator/6690221911506944


Solution

  • This is because of your call to btnx.draw.handleMouseClick() inside of your mouseClicked function. If you change it to the following, it will work as expected:

    mouseClicked = function() {
        btn7.handleMouseClick();
        btn8.handleMouseClick();
        btn9.handleMouseClick();
        btndiv.handleMouseClick();
        btn4.handleMouseClick();
        btn5.handleMouseClick();
        btn6.handleMouseClick();
        btn1.handleMouseClick();
        btn2.handleMouseClick();
        btn3.handleMouseClick();
        btnsub.handleMouseClick();
        btn0.handleMouseClick();
        btnc.handleMouseClick();
        btnadd.handleMouseClick();
        btnequal.handleMouseClick();
        btnx.draw.handleMouseClick();
    };
    

    Update: Looks like you updated the code for your calculator app, and removed the btnx.draw.handleMouseClick function call - which also seems to work.