Open Aqeelabdullah opened 3 weeks ago
function calculator() { let choice;
do { console.log("Make a selection:"); console.log("1) +"); console.log("2) -"); console.log("3) *"); console.log("4) /"); console.log("5) Power of"); console.log("6) Quit");
choice = parseInt(prompt("Enter your choice (1-6):"));
switch (choice) {
case 1:
let num1 = parseFloat(prompt("Enter the first number:"));
let num2 = parseFloat(prompt("Enter the second number:"));
let sum = num1 + num2;
console.log("Sum:", sum);
break;
case 2:
num1 = parseFloat(prompt("Enter the first number:"));
num2 = parseFloat(prompt("Enter the second number:"));
let difference = num1 - num2;
console.log("Difference:", difference);
break;
case 3:
num1 = parseFloat(prompt("Enter the first number:"));
num2 = parseFloat(prompt("Enter the second number:"));
let product = num1 * num2;
console.log("Product:", product);
break;
case 4:
num1 = parseFloat(prompt("Enter the first number:"));
num2 = parseFloat(prompt("Enter the second number:"));
if (num2 === 0) {
console.log("Error: Division by zero is not allowed.");
} else {
let quotient = num1 / num2;
console.log("Quotient:", quotient);
}
break;
case 5:
num1 = parseFloat(prompt("Enter the base number:"));
num2 = parseFloat(prompt("Enter the exponent:"));
let power = Math.pow(num1, num2);
console.log("Power:", power);
break;
case 6:
console.log("Exiting the calculator.");
break;
default:
console.log("Invalid choice. Please enter a number between 1 and 6.");
}
} while (choice !== 6); }
calculator();
function calculator() { let choice;
do { console.log("Make a selection:"); console.log("1) +"); console.log("2) -"); console.log("3) *"); console.log("4) /"); console.log("5) Power of"); console.log("6) Quit");
} while (choice !== 6); }
calculator();