1 Replies - 8597 Views - Last Post: 18 March 2013 - 11:00 AM

#1 jesders88  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 46
  • Joined: 25-October 12

calculator

Posted 18 March 2013 - 10:40 AM

So I am so new to javascript. I need to build a calculator.
1. It must not use eval at all
2. It must not be in a table
3. The Javascript must use only one function for all the calculations.
4. I must not use onclick, I have to use an event listener.

I am not looking for someone to do my homework but someone to explain in a step by step process what to do or help with how to do it. I dont even know how to get around eval. Ill post the basic design of my calculator.

<html>
<head>
<title>Calculator</title>
<script src = script.js></script>

</head>
<body>
<input type = "text" id = "calculatorInput" size = "26"/>
<input type = "button" id = "equalsButton" value = "      =      "/><br>
<input type = "button" id = "oneButton" value = "  1  "/>
<input type = "button" id = "twoButton" value = "  2  "/>
<input type = "button" id = "threeButton" value = "  3  "/>
<input type = "button" id = "plusButton" value = "   +   "/><br>
<input type = "button" id = "fourButton" value = "  4  "/>
<input type = "button" id = "fiveButton" value = "  5  "/>
<input type = "button" id = "sixButton" value = "  6  "/>
<input type = "button" id = "minusButton" value = "    -   "/><br>
<input type = "button" id = "sevenButton" value = "  7  "/>
<input type = "button" id = "eightButton" value = "  8  "/>
<input type = "button" id = "nineButton" value = "  9  "/>
<input type = "button" id = "timesButton" value = "    *   "/><br>
<input type = "button" id = "decimalButton" value = "   .  "/>
<input type = "button" id = "zeroButton" value = "  0  "/>
<input type = "button" id = "clearButton" value = "  C  "/>
<input type = "button" id = "divideButton" value = "   /    "/><br>

</body> 
</html>



Is This A Good Question/Topic? 0
  • +

Replies To: calculator

#2 andrewsw  Icon User is offline

  • Fire giant boob nipple gun!
  • member icon

Reputation: 2885
  • View blog
  • Posts: 9,575
  • Joined: 12-December 12

Re: calculator

Posted 18 March 2013 - 11:00 AM

It would help if you remove all those spaces from the values, you will need these values later. Use CSS if you want the buttons to be wider.

I would rename the buttons id="button0" to id="button9" as this may also be useful later.

You should start with addEventListenter to attach events to the buttons.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1