0% found this document useful (0 votes)
5 views

calculator code

Uploaded by

neevp5772
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

calculator code

Uploaded by

neevp5772
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

<html>

<head>

<script>

//function that display value

Function dis(val)

Document.getElementById(“result”).value+=val

//function that evaluates the digit and return result

Function solve()

Let x = document.getElementById(“result”).value

Let y = eval(x)
Document.getElementById(“result”).value = y

//function that clear the display

Function clr()

Document.getElementById(“result”).value = “”

</script>

<!—for styling 

<style>

.title{

Margin-bottom: 10px;

Text-align:center;

Width: 210px;
Color:green;

Border: solid black 2px;

Input[type=”button”]

Background-color:green;

Color: black;

Border: solid black 2px;

Width:100%

Input[type=”text”]

{
Background-color:white;

Border: solid black 2px;

Width:100%

</style>

</head>

<!—create table 

<body>

<div class = title >GeeksforGeeks Calculator</div>

<table border=”1”>

<tr>

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

<!—clr() function will call clr to clear all value 

<td><input type=”button” value=”c” onclick=”clr()”/> </td>

</tr>
<tr>

<!—create button and assign value to each button 

<!—dis(“1”) will call function dis to display value 

<td><input type=”button” value=”1” onclick=”dis(‘1’)”/> </td>

<td><input type=”button” value=”2” onclick=”dis(‘2’)”/> </td>

<td><input type=”button” value=”3” onclick=”dis(‘3’)”/> </td>

<td><input type=”button” value=”/” onclick=”dis(‘/’)”/> </td>

</tr>

<tr>

<td><input type=”button” value=”4” onclick=”dis(‘4’)”/> </td>

<td><input type=”button” value=”5” onclick=”dis(‘5’)”/> </td>

<td><input type=”button” value=”6” onclick=”dis(‘6’)”/> </td>

<td><input type=”button” value=”-“ onclick=”dis(‘-‘)”/> </td>

</tr>
<tr>

<td><input type=”button” value=”7” onclick=”dis(‘7’)”/> </td>

<td><input type=”button” value=”8” onclick=”dis(‘8’)”/> </td>

<td><input type=”button” value=”9” onclick=”dis(‘9’)”/> </td>

<td><input type=”button” value=”+” onclick=”dis(‘+’)”/> </td>

</tr>

<tr>

<td><input type=”button” value=”.” Onclick=”dis(‘.’)”/> </td>

<td><input type=”button” value=”0” onclick=”dis(‘0’)”/> </td>

<!—solve function call function solve to evaluate value 

<td><input type=”button” value=”=” onclick=”solve()”/> </td>

<td><input type=”button” value=”*” onclick=”dis(‘*’)”/> </td>

</tr>

</table>

</body>
</html>

You might also like