Practical 03

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Practical 03 :-

<!DOCTYPE html>

<html>

<head>

<title>Simple Calculator</title>

</head>

<body>

<h1>Simple Calculator</h1>

<label for="num1">Enter first number:</label>

<input type="number" id="num1">

<br>

<label for="num2">Enter second number:</label>

<input type="number" id="num2">

<br>

<button onclick="calculate('sum')">Sum</button>

<button onclick="calculate('product')">Product</button>

<button onclick="calculate('difference')">Difference</button>

<button onclick="calculate('quotient')">Quotient</button>

<br>

<p id="result"></p>

<script> function calculate(operation) { var num1 =

parseFloat(document.getElementById('num1').value); var num2

= parseFloat(document.getElementById('num2').value);

var result; switch

(operation) { case 'sum':


result = num1 + num2;

break;

case 'product':

result = num1 * num2;

break; case 'difference':

result = num1 - num2;

break; case 'quotient':

if (num2 !== 0) {

result = num1 / num2;

} else { result =

"Cannot divide by zero!";

break;

default:

result = "Invalid operation";


}

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

</script>

</body>

</html>
Output :-

Practical 03 Date :-
No :-
Name :- Nikita Valmik kirtikar Roll No 26128
:-
Sign :- Grade
:-

You might also like