JavaScript Project: Learn How to Build a Calculator From Scratch Using JavaScript

In this tutorial, i will teach you how to build a simple calculator using JavaScript.
This tutorial assume that you’re not a novice in HTML and CSS, so i won’t explain the HTML and CSS codes in details. If you wish you to learn HTML, CSS and Bootstrap, [B]click here to follow my live coding thread here [/B]

Feel free to ask to drop your questions below or contact me if you have any projects you want to execute. PM me or Email: [email protected]

Calculator Demo

We’ll need two files for this simple project: HTML and CSS file. Our JavaScript will be In-line JavaScript.

[CODE=html]

Simple JavaScript mainCalculator

Simple JavaScript Calculator






[/CODE]

In the HTML code above, the JavaScript onclick event performs the calculator when a button input is called. It performs to operation using the form id, text input name and the value. for 0 to 9 inputs, it adds the value to the form text input area. For the 0 input field, the value in the onclick event isn’t enclosed in a quote ’ '.

For equal to operator, we use the evaluation function eval() to evaluate the form id, text input name and the value and also you don’t include the plus sign (+) because you’re not adding it to the text input area. For clear (c), we keep and empty space between the quotes ’ ’ which tells the device to empty the input field when the button is clicked.

[CODE]#calculatorWrapper {
width: 600px;
height: auto;
background: #000;
border: 3px solid rgb(255, 0, 0);
border-radius: 15px;
margin: 0 auto;
}

input[type=button] {
width: 20%;
margin: 2%;
font-size: 20px;
font-weight: 600px;
line-height: 1.5;
color: #fff;
background: #553945;
border: 1px solid yellow;
}

input[type=button]:hover {
color: #ff0000;
}

input[type=text] {
width: 90%;
font-size: 20px;
margin: 1% 1% 1% 4%;
color: #ff0000;
background:#fff;
font-weight: bold;
border: 2px solid yellow;
}

input[type=text]:hover {
background: rgb(241, 216, 216);
border: 3px double blue;
}

h1 {
text-align: center;
}[/CODE]

[SIZE=5]You should get This[/SIZE]

[ATTACH=full]264674[/ATTACH]

That’s it. You’ve created a simple JavaScript with the aid of in-line JavaScript onclick event.

Let me know if you have any difficulty while doing this.

Thank you

You’re Welcome Chatur.

unafaa ulezee mtu venye pia anasave code kuna wenye hawajui

Using a translator to translate to English, you wrote

you have to point out the person who is also coding the code for the unaware

Can you make your statement clearer?

explain how somebody is supposed to save a file. (file type). There some who don’t know

[ul]
[li]To save a HTML file, save the document with (.html) extension. for instance index.html, calculator.html[/li][li]To save a CSS file, save the document with (.css) extension. for instance styles.css.[/li][li]For JavaScript, (.js), i.e styles.js[/li][li]For PHP (.php) i.e contact.php[/li][li]For Python (.py) i.e contact.py[/li][/ul]

It is cool when you have the skill and knowledge to build a calculator, but most of us couldn’t do it even with your code written. I always needed a calculator and converter because I can’t get used to the metric system. I found a website where you can do both. I have the need to convert stuff like “150 lbs to kg” all the time and it is nice to know that you can do it in a few seconds. You can convert everything you need on there and even check the weather. It is the most complete website, you calculate and convert everything. It is a good solution for the people that don’t know how to build their own calculator.

Really cool converter, thanks for sharing this!

Hello! I have been hunting for a job at [COLOR=rgb(0, 0, 0)] https://devoxsoftware.com/blog/angular-developer-salary-research/ for a while now. They announced some vacancies last week. In order to gain more confidence I decided to do some exercising and train in JavaScript as it is one of their main requirements. Small coding like creating a calculator has been very helpful. At first I thought that it would be complicated but I seem to be managing just fine. I notice that after gaining some knowledge about this language you basically start translating everything about into it.