-3

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

Sam Chen
  • 1
  • 1
  • That JavaScript code is ugly, for lack of a better word; I hope that's not how they're teaching you to code at Khan Academy. And for future reference, if you want to avoid down-votes: Describe what the problem is exactly and what you expected to happen. And also post your code, don't link to it. – chipit24 Nov 06 '16 at 15:17

1 Answers1

0

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.

Pang
  • 9,564
  • 146
  • 81
  • 122
chipit24
  • 6,509
  • 7
  • 47
  • 67