You are on page 1of 7

SOURCE CODE:

<html>

<head>

<title>calculator</title>

<style>

Body{

padding:100px 500px;

section{

border:10px solid;

padding-bottom:50px;

input[type="button"]

background-color:white;

border:solid black 2px;

width:100%

input[type="text"]

background-color:white;

border:solid black 2px;


width:100%

#but1:hover,#but2:hover,#but3:hover,#but4:hover,#but5:hover;

background-color:black;

cursor:pointer;

</style>

</head>

<body>

<center>

<section>

<h1>Simple Calculator</h1>

<table border="1">

<tr>

<td colspan="3"><input type="text" id="result"/></td>

<td><input type="button" value="C" onclick="clr()"/></td>

</tr>

<tr>

<td><input type="button" id="but1" value="1" onclick="view('1')"/></td>

<td><input type="button" id="but1" value="2" onclick="view('2')"/></td>


<td><input type="button" id="but1" value="3" onclick="view('3')"/></td>

<td><input type="button" id="but1" value="/" onclick="view('/')"/></td>

</tr>

<tr>

<td><input type="button" id="but2" value="4" onclick="view('4')"/></td>

<td><input type="button" id="but2" value="5" onclick="view('5')"/></td>

<td><input type="button" id="but2" value="6" onclick="view('6')"/></td>

<td><input type="button" id="but2" value="-" onclick="view('-')"/></td>

</tr>

<tr>

<td><input type="button" id="but3" value="7" onclick="view('7')"/></td>

<td><input type="button" id="but3" value="8" onclick="view('8')"/></td>

<td><input type="button" id="but3" value="9" onclick="view('9')"/></td>

<td><input type="button" id="but3" value="+" onclick="view('+')"/></td>

</tr>

<tr>

<td><input type="button" id="but4" value="." onclick="view('.')"/></td>

<td><input type="button" id="but4" value="0" onclick="view('0')"/></td>

<td><input type="button" id="but4" value="=" onclick="compute()"/></td>

<td><input type="button" id="but4" value="*" onclick="view('*')"/></td>

</tr>

</table><br>
<button id="but5" onclick="cgpa()"
style=backgroundcolor:grey;>CGPA</button>

<button id="but5" onclick="remo()" style=backgroundcolor:grey;>ERC</button>

</section>

</center>

</body>

</html>

<script>

function view(num)

document.getElementById("result").value+=num

function compute()

let x=document.getElementById("result").value

let y=eval(x)

document.getElementById("result").value=y

function clr()

document.getElementById("result").value=""

}
function remo()

var str=document.getElementById("result").value;

str=str.substring(0,str.length-1);

document.getElementById("result").value=str;

function cgpa()

document.getElementById("result").value=(document.getElementById("result").value)/9.5;

</script>

You might also like