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

Arithmetic

The document describes a JavaScript program that performs arithmetic operations. It takes in two numbers and an operation as input, performs the calculation, and displays the output. The program uses a switch statement to select the appropriate operation - addition, subtraction, multiplication, or division - and calculate the result. It handles division by zero as a special case by returning an error message. The program was tested and the output was successfully verified.

Uploaded by

Padmanaban M
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)
32 views

Arithmetic

The document describes a JavaScript program that performs arithmetic operations. It takes in two numbers and an operation as input, performs the calculation, and displays the output. The program uses a switch statement to select the appropriate operation - addition, subtraction, multiplication, or division - and calculate the result. It handles division by zero as a special case by returning an error message. The program was tested and the output was successfully verified.

Uploaded by

Padmanaban M
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/ 3

211421205125

ARITHMETIC OPERATIONS

AIM:
To write a JavaScript program that performs arithmetic operations with the given numbers
and provides the result.

ALGORITHM:
Step 1: Start the process.

Step 2: Read and store the first number.

Step 3: Read and store the second number.

Step 4: Read and store the desired arithmetic operation.

Step 5: Perform the selected operation.

Step 6: Display the result.

Step 7: Stop the process.

PROGRAM:
<!DOCTYPE html>
<html>
<head>
<title>Arithmetic Operations</title>
</head>
<body>
<h1>Arithmetic Operations</h1>
<form id="calculator">
<label for="num1">Enter Number 1:</label>
<input type="number" id="num1" name="num1" required><br><br>
<label for="num2">Enter Number 2:</label>
<input type="number" id="num2" name="num2" required><br><br>
<label for="operation">Select Operation:</label>
<select id="operation" name="operation">
<option value="add">Addition</option>
<option value="subtract">Subtraction</option>
<option value="multiply">Multiplication</option>
211421205125

<option value="divide">Division</option>
</select><br><br>
<input type="button" value="Calculate" onclick="calculate()">
</form>
<h2>Result:</h2>
<p id="result"></p>
<script> function
calculate() {
const num1 = parseFloat(document.getElementById('num1').value);
const num2 =
parseFloat(document.getElementById('num2').value); const
operation = document.getElementById('operation').value;
let result;
switch (operation) {
case 'add':
result = num1 + num2;
break;
case 'subtract':
result = num1 - num2;
break;
case 'multiply':
result = num1 * num2;
break;
case 'divide':
if (num2 === 0) {
result = "Division by zero is not allowed.";
}
else {
result = num1/num2;
}
break;
default:
result = "Invalid operation";
}
211421205125

document.getElementById('result').textContent = `Result: $
{result}`;
}
</script>
</body>
</html>

OUTPUT:

RESULT:
Thus the JavaScript program to perform arithmetic operations with the given two numbers
was executed and the output has been verified successfully.

You might also like