KEMBAR78
Answers of Javascript | PDF
0% found this document useful (0 votes)
8 views2 pages

Answers of Javascript

This document is an HTML code for a simple calculator web application. It allows users to input two numbers and perform basic arithmetic operations: addition, subtraction, multiplication, and division. The result is displayed on the webpage after the operation is performed.

Uploaded by

NEHA SHARMA
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)
8 views2 pages

Answers of Javascript

This document is an HTML code for a simple calculator web application. It allows users to input two numbers and perform basic arithmetic operations: addition, subtraction, multiplication, and division. The result is displayed on the webpage after the operation is performed.

Uploaded by

NEHA SHARMA
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/ 2

<!

DOCTYPE html>

<html>

<head><title>Calculator</title></head>

<body>

<input type="number" id="num1" placeholder="Enter first number">

<input type="number" id="num2" placeholder="Enter second number"><br><br>

<button onclick="calculate('+')">Add</button>

<button onclick="calculate('-')">Subtract</button>

<button onclick="calculate('*')">Multiply</button>

<button onclick="calculate('/')">Divide</button>

<h3 id="result"></h3>

<script>

function calculate(op) {

let a = parseFloat(document.getElementById("num1").value);

let b = parseFloat(document.getElementById("num2").value);

let res;

switch(op) {

case '+': res = a + b; break;

case '-': res = a - b; break;

case '*': res = a * b; break;

case '/': res = b !== 0 ? a / b : "Cannot divide by zero"; break;

document.getElementById("result").innerText = "Result: " + res;

</script>
</body>

</html>

You might also like