How To Make A Calculator

Table of contents:

How To Make A Calculator
How To Make A Calculator

Video: How To Make A Calculator

Video: How To Make A Calculator
Video: Build A Calculator With JavaScript Tutorial 2024, December
Anonim

Since the introduction of modern electronic technologies into the daily life of people, a variety of electronics and computer equipment have been used in absolutely all areas of activity. Today, many sites provide services in which you need to recalculate certain indicators - for example, online stores, in which you need to add up the total amount of the ordered product. In this case, an online calculator comes to your aid, built into the site code, which allows you to calculate any combination of numbers at any time. It's easy to embed a calculator on your website, and in this article, we'll show you how.

How to make a calculator
How to make a calculator

Instructions

Step 1

In order to embed in the code of any page of your site the simplest form of a calculator that allows you to add any two numbers and get the result, use the following code, which contains two fields for entering text (input), an addition sign and an equal sign, and a button for derivation of the calculation result:

+ =

Step 2

Now, take a look at the content of your calculator's code:

function calc ()

{

var num1 = parseInt (document.getElementById ("num1"). value);

var num2 = parseInt (document.getElementById ("num2"). value);

var res = document.getElementById ("result");

res.innerHTML = num1 + num2;

}

Step 3

The code takes effect after you click the "Calculate" button in the above form - it calls the calc () function. Assign values to variables num1, num2 and res as the first, second and third (resultant) parameters.

Step 4

Each variable is followed by a parseInt property that converts the data to an integer type. The calculation you get here is wrapped in the span tag - after that, your calculator is ready.

Step 5

With the proper skill, a calculator can be created and integrated into a website in no more than ten minutes.

Recommended: