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

Program 6

This document is an HTML program that creates a simple calculator with various operations including addition, subtraction, multiplication, division, squaring a number, raising a number to a power, and calculating the square root. It uses JavaScript to perform calculations based on user input from two number fields and a dropdown menu for selecting the operation. The result is displayed on the webpage after clicking the 'Calculate' button.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views3 pages

Program 6

This document is an HTML program that creates a simple calculator with various operations including addition, subtraction, multiplication, division, squaring a number, raising a number to a power, and calculating the square root. It uses JavaScript to perform calculations based on user input from two number fields and a dropdown menu for selecting the operation. The result is displayed on the webpage after clicking the 'Calculate' button.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Program 6:

<!DOCTYPE html>

<html>

<body>

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

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

<select id="op">

<option value="+">+</option>

<option value="-">-</option>

<option value="*">*</option>

<option value="/">/</option>

<option value="square">Square</option>

<option value="power">Power</option>

<option value="sqrt">Square Root</option>

</select>

<button onclick="calc()">Calculate</button>

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

<script>

function calc() {

const num1 = parseFloat(document.getElementById('num1').value);

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

const op = document.getElementById('op').value;

let result;

switch (op) {

case '+':
result = num1 + num2;

break;

case '-':

result = num1 - num2;

break;

case '*':

result = num1 * num2;

break;

case '/':

result = num1 / num2;

break;

case 'square':

result = Math.pow(num1, 2);

break;

case 'power':

result = Math.pow(num1, num2);

break;

case 'sqrt':

result = Math.sqrt(num1);

break;

document.getElementById('result').innerHTML = result;

</script>

</body>

</html>
Output:

You might also like