0% found this document useful (0 votes)
47 views2 pages

Cal HTML

The document describes a simple HTML/JavaScript calculator with numeric buttons, operators, and functions to append values to the display, clear the display, and evaluate the expression.

Uploaded by

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

Cal HTML

The document describes a simple HTML/JavaScript calculator with numeric buttons, operators, and functions to append values to the display, clear the display, and evaluate the expression.

Uploaded by

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

<!

DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Simple Calculator</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
margin: 50px;
}
input[type="button"] {
width: 50px;
height: 50px;
font-size: 18px;
margin: 5px;
}
input[type="text"] {
width: 200px;
height: 50px;
font-size: 18px;
margin-bottom: 10px;
}
</style>
</head>
<body>

<h2>Simple Calculator</h2>
<input type="text" id="display" readonly>

<br>

<script>
function appendToDisplay(value) {
document.getElementById('display').value += value;
}

function clearDisplay() {
document.getElementById('display').value = '';
}

function calculate() {
try {
document.getElementById('display').value =
eval(document.getElementById('display').value);
} catch (error) {
document.getElementById('display').value = 'Error';
}
}
</script>

<input type="button" value="7" onclick="appendToDisplay('7')">


<input type="button" value="8" onclick="appendToDisplay('8')">
<input type="button" value="9" onclick="appendToDisplay('9')">
<input type="button" value="/" onclick="appendToDisplay('/')">

<br>
<input type="button" value="4" onclick="appendToDisplay('4')">
<input type="button" value="5" onclick="appendToDisplay('5')">
<input type="button" value="6" onclick="appendToDisplay('6')">
<input type="button" value="-" onclick="appendToDisplay('-')">

<br>

<input type="button" value="1" onclick="appendToDisplay('1')">


<input type="button" value="2" onclick="appendToDisplay('2')">
<input type="button" value="3" onclick="appendToDisplay('3')">
<input type="button" value="+" onclick="appendToDisplay('+')">

<br>

<input type="button" value="0" onclick="appendToDisplay('0')">


<input type="button" value="." onclick="appendToDisplay('.')">
<input type="button" value="C" onclick="clearDisplay()">
<input type="button" value="=" onclick="calculate()">

</body>
</html>

You might also like