# Javascript - Simple Calculator

In this tutorial we will create a Simple Calculator using Javascript. JavaScript is a scripting or programming language that allows you to implement complex things on web pages. It is widely used in designing a stunning website. It is an interpreted programming language that has a capabilities of Object-Oriented. This code can be used as your calculator to any mathematical problem. So Let's do the coding.

## Before we started:

First you have to download & install XAMPP or any local server that run PHP scripts. Here's the link for XAMPP server https://www.apachefriends.org/index.html.

And this is the link for the bootstrap that has been used for the layout of the calculator https://getbootstrap.com/

## The Main Function

This code contains the main function of the application. This code is the source code of the calculator that display the designed of the application. This will calculate the equation when the equal button is pressed. To create this just write these block of code inside the text editor.

`<!DOCTYPE html><html lang="en">	<head>		<link rel="stylesheet" type="text/css" href="css/bootstrap.css"/>		<meta charset="UTF-8" name="viewport" content="width-device-width, initial-scale=1"/>	</head><body>	<nav class="navbar navbar-default">		<div class="container-fluid">			<a class="navbar-brand" href="https://sourcecodester.com">Sourcecodester</a>		</div>	</nav>	<div class="col-md-3"></div>	<div class="col-md-6 well">		<h3 class="text-primary">Javascript - Simple Calculator</h3>		<hr style="border-top:1px dotted #ccc;"/>		<div class="col-md-2"></div>		<div class="col-md-8">			<div class="col-md-1"></div>			<div class="col-md-10 well" style="background-color:#ccc;">			<form name="calculator">				<input type="text" name="result" style="width:100%; height:50px; font-size:30px;">				<br /><br />				<button type="button" onclick="calculator.result.value+='1'" style="padding:25px; margin-left:5px; font-size:14px;">1</button>				<button type="button" onclick="calculator.result.value+='2'" style="padding:25px; font-size:14px;" >2</button>				<button type="button" onclick="calculator.result.value+='3'" style="padding:25px; font-size:14px;">3</button>				<button type="button" onclick="calculator.result.value+='+'" style="padding:25px; font-size:14px;">+</button>				<br /><br />				<button type="button" onclick="calculator.result.value+='4'"  style="padding:25px; margin-left:5px; font-size:14px;">4</button>				<button type="button" onclick="calculator.result.value+='5'"  style="padding:25px; font-size:14px;">5</button>				<button type="button" onclick="calculator.result.value+='6'"  style="padding:25px; font-size:14px;">6</button>				<button type="button" onclick="calculator.result.value+='-'"  style="padding-top:25px; padding-bottom:25px; padding-right:27px; padding-left:27px; font-size:14px;">-</button>				<br /><br />				<button type="button" onclick="calculator.result.value+='7'"  style="padding:25px; margin-left:5px; font-size:14px;">7</button>				<button type="button" onclick="calculator.result.value+='8'"  style="padding:25px; font-size:14px;">8</button>				<button type="button" onclick="calculator.result.value+='9'"  style="padding:25px; font-size:14px;">9</button>				<button type="button" onclick="calculator.result.value+='*'"  style="padding-top:25px; padding-bottom:25px; padding-right:26px; padding-left:26px; font-size:13px;">x</button>				<br /><br />				<button type="button" onclick="calculator.result.value =''"  style="padding:25px; margin-left:5px; font-size:14px;">C</button>				<button type="button" onclick="calculator.result.value+='0'"  style="padding:25px; font-size:14px;">0</button>				<button type="button" onclick="calculator.result.value=eval(calculator.result.value)"  style="padding:25px; font-size:14px;">=</button>				<button type="button" onclick="calculator.result.value+='/'"  style="padding-top:25px; padding-bottom:25px; padding-right:26px; padding-left:26px; font-size:14px;">/</button>			</form>			</div>		</div>	</div></body></html>`

There you have it we successfully created a Simple Calculator using Javascript. I hope that this simple tutorial help you to what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!!!

### Tags

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.