[go: up one dir, main page]

0% found this document useful (0 votes)
8 views3 pages

Calculator

Uploaded by

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

Calculator

Uploaded by

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

Here's a simple example of an HTML calculator using JavaScript for basic arithmetic operations:

```html

<!DOCTYPE html>

<html>

<head>

<title>HTML Calculator</title>

<style>

.calculator {

width: 200px;

padding: 10px;

border: 1px solid #ccc;

</style>

</head>

<body>

<div class="calculator">

<input type="text" id="result" readonly>

<br>

<button onclick="appendToResult('1')">1</button>

<button onclick="appendToResult('2')">2</button>

<button onclick="appendToResult('3')">3</button>

<button onclick="appendToResult('+')">+</button>

<br>

<button onclick="appendToResult('4')">4</button>
<button onclick="appendToResult('5')">5</button>

<button onclick="appendToResult('6')">6</button>

<button onclick="appendToResult('-')">-</button>

<br>

<button onclick="appendToResult('7')">7</button>

<button onclick="appendToResult('8')">8</button>

<button onclick="appendToResult('9')">9</button>

<button onclick="appendToResult('*')">*</button>

<br>

<button onclick="appendToResult('0')">0</button>

<button onclick="appendToResult('.')">.</button>

<button onclick="calculateResult()">=</button>

<button onclick="appendToResult('/')">/</button>

<br>

<button onclick="clearResult()">Clear</button>

</div>

<script>

function appendToResult(value) {

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

function calculateResult() {

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

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

function clearResult() {

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

</script>

</body>

</html>

```

This example creates a basic calculator interface with buttons for numbers, arithmetic operations, and a
text input field to display the result. JavaScript functions are used to handle button clicks, append values
to the result, perform calculations, and clear the result. Note that the `eval()` function is used to
evaluate the mathematical expression entered in the input field and calculate

You might also like