In this article you learn how to use to Java Script to create a Circle⁄Sphere calculator. The user enters the radius of a circle or sphere, and the calculator returns the area, circumference, surface area, and volume. The process for coding any calculator can be broken down into a step-by-step procedure.
Welcome to Bucaro TecHelp!

Welcome to Bucaro TecHelp!
Maintain Your Computer and Use it More Effectively
to Design a Web Site and Make Money on the Web

[About BTH]  [User Agreement]  [Privacy Policy]  [Site Map]  [Contact Form]  [Advertise on BTH]  [News Feed]

Google
Web
This Site
Your Ad Here!
Your ad here for one full year, only $20. Send me your ad copy, up to six lines, I'll post it ASAP. After you inspect your ad online, you can pay through PayPal.
Click here for more information.

Code for Java Script Circle⁄Sphere Calculator

Circumference:
Circle Area:
Sphere Surface Area:
Sphere Volume:
Enter Radius:

In this article I'll show you how to use to Java Script to create a Circle ⁄ Sphere calculator. With this calculator, the user inputs the radius of a circle or sphere, and the calculator will return the area and circumference (if a circle) or the surface area and volume (if a sphere). I'll explain in detail so that you can learn Java Script and modify the code for your own purposes.

I have programmed many Java Script calculators and discovered that, the process for coding any calculator can be broken down into a step-by-step procedure. Shown below are the steps to build a calculator.

1. Acquire the formula
2. Determine the inputs and outputs
3. Design the html form
4. Write the Java Script to process the form
5. Display the results of the calculation
6. Provide code to handle errors

Note that in step 4 you write the Java Script to process the form, which would include displaying the results, but I listed displaying the results in step 5. The reason for that is that the output usually needs to be formatted and this requires a little additional code. The same thing with step 6. You can't rely on the user to enter proper inputs into the form, in step 6 we need to ad code to validate the input data.

Step 1: Circle and Sphere Formula

Shown below are the formulas we'll use for the Circle ⁄ Sphere calculator:

circle circumference = 2 * Pi * r

circle area = pi * r²

sphere surface area = 4 * pi * r³

sphere volume = 4⁄3 (pi * r³)

Step 2: Determine the Inputs and Outputs

As stated at the beginning of this article, the user will input the radius of a circle or sphere, and the calculator will return the area and circumference (if a circle) or the surface area and volume (if a sphere). Those are the mathematical inputs and outputs, but we have several other inputs and outputs to consider.

We could complicate the heck out of this calculator and get involved in the units and unit conversions. But the fact of the matter is, these circle and sphere formulas don't care about the units, that is, the units in are the units out. We could design the calculator to perform units conversions (e.g. inches to feet or yards to meters) but to keep this example simple, I'm just going to ignore the units.

Web Design Sections

RSS Feed RSS Feed

Easy Java Script Code
Easy Java Script Timer Code
Easy Java Script Windows
Easy Rollovers
Easy Picture Transition Effects
Easy Moving Popup Code
Easy Slide Show Code
Easy Slide Show Code With Linked Slides
Slide Show with Different Size Images
Easy Picture Zoom Code
Easy Picture Panning Code
Easy Java Script Animation
Easy JavaScript Picture Selector Code
Easy Animated Banners with Java Script
Easy Java Script Form Validation
Easy Drag n Drop Code
Easy Graph Generating Code
Easy Code to Sort a Table by Column
Web Designer's Reference
Easy Fading Text Banner Code
Easy Expanding Banner Code
Calendars for Your Website
Date Picker For Your Web Site
Calculators For Your Web Site
Loan Payment Calculator
Length Units Converter
Body Mass Index
Fahrenheit to Celsius Converter
Decimal to Hexidecimal Converter
Easy Code for Screen Tape Adding Machine
Code for Java Script Circle⁄Sphere Calculator
Round a Float to 4 Digits to the Right of the Decimal Point
Make Your Own Graphical Digital Clock
Let Your Web site Visitors Set Font Size
How to Disable the Browser Back Button
Add More Bang to Your Content With Keyword Popup Menus
Put a Music Off Switch on Your Webpage
Java Script Random Password Generator
Password Protection Using Java Script
Replace Drop-down with Drag-and-drop
Submit Forms Without CGI
Code for a Less annoying Popup Window
Using the Java Script Array Object
Using the Java Script Date Object
Java Script Message Boxes
How to Shuffle the Deck With Java Script
Web Site Menus : Which Section Am I In?
How Far Did the User Scroll?
Where Did the User Click?
Four Ways to Use Java Script Event Handlers
Create Your Own Database Using Only Notepad : CDV

[Site User Agreement]  [Advertise on This site]  [Search This Site]  [Contact Form]
Copyright©2001-2007 Bucaro TecHelp P.O.Box 18952 Fountain Hills, AZ 85269