Home arrow HTML arrow Page 4 - Coding a Web Page Calculator
HTML

Coding a Web Page Calculator


Welcome to the second part of a six-part series on how to build a calculator for your web page. In the previous part, we got into the basics of setting up the calculator's layout and what functions we want it to have. In this part, we will begin to code the functions.

Author Info:
By: Chrysanthus Forcha
Rating: 5 stars5 stars5 stars5 stars5 stars / 1
March 11, 2009
TABLE OF CONTENTS:
  1. · Coding a Web Page Calculator
  2. · Code Basics
  3. · The showNum() Function
  4. · The operator() Function
  5. · Explanation of the operator() Function

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Coding a Web Page Calculator - The operator() Function
(Page 4 of 5 )

The other function, operator(), carries out operations. It has to carry out the ADD, SUBTRACT, MULTIPLY and DIVIDE operations. It also has to store, clear the display and do evaluation (Enter). This is its function skeleton with its associated global variables:


var evalString = ""


var memVar = "";


var toClearDisplay = false;


function operator(ID)

{

//first construct the first part of the eval argument using JavaScrip’s top level eval() function


switch (ID)

{

case "BP":

//join “ “ and “+” and “ “ to the evaluation string, evalString.

break;

case "BMI":

//join “ “ and “-” and “ “ to the evaluation string, evalString.

break;

case "BX":

//join “ “ and “*” and “ “ to the evaluation string, evalString.

break;

case "BD":

//join “ “ and “/” and “ “ to the evaluation string, evalString.

break;

case "BMP":

// Store display content into memory

break;

case "BMM":

//Clear the display and do other associated things.

break;

case "BEQ":

//Evaluate the mathematical expression.

break;

}

}




blog comments powered by Disqus
HTML ARTICLES

- HTML5 Boilerplate: Working with jQuery and M...
- HTML5 Boilerplate Introduction
- New API Platform for HTML5
- BBC Adopts HTML 5, Mozilla Addresses Issues
- Advanced Sticky Footers in HTML and CSS
- HTML and CSS Sticky Footers
- Strategy Analytics Predicts HTML5 Phones to ...
- HTML5 Guidelines for Web Developers
- Learning HTML5 Game Programming
- More Engaging CSS3 and HTML Background Effec...
- Engaging HTML and CSS3 Background Effects
- More Web Columns with CSS3 and HTML
- Columns with CSS3 and HTML
- Creating Inline-Block HTML Elements with CSS
- Drag and Drop in HTML5: Parsing Local Files

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 8 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials