Shopping cart

Subtotal $0.00

View cartCheckout

Tools

function add(x, y) { return x + y; } function subtract(x, y) { return x - y; } function multiply(x, y) { return x * y; } function divide(x, y) { if (y === 0) { return "Error! Division by zero."; } else { return x / y; } } function power(x, y) { return Math.pow(x, y); } function squareRoot(x) { if (x < 0) { return "Error! Square root of a negative number."; } else { return Math.sqrt(x); } } function logarithm(x, base) { if (x <= 0 || base <= 0) { return "Error! Logarithm base and argument must be positive."; } else { return Math.log(x) / Math.log(base); } } console.log("Select operation:"); console.log("1. Add"); console.log("2. Subtract"); console.log("3. Multiply"); console.log("4. Divide"); console.log("5. Power"); console.log("6. Square Root"); console.log("7. Logarithm"); while (true) { var choice = prompt("Enter choice (1/2/3/4/5/6/7): "); if (['1', '2', '3', '4', '5', '6', '7'].includes(choice)) { if (choice === '6') { var num = parseFloat(prompt("Enter number: ")); console.log("Result:", squareRoot(num)); } else if (choice === '7') { var num = parseFloat(prompt("Enter number: ")); var base = parseFloat(prompt("Enter base: ")); console.log("Result:", logarithm(num, base)); } else { var num1 = parseFloat(prompt("Enter first number: ")); var num2 = parseFloat(prompt("Enter second number: ")); if (choice === '1') { console.log("Result:", add(num1, num2)); } else if (choice === '2') { console.log("Result:", subtract(num1, num2)); } else if (choice === '3') { console.log("Result:", multiply(num1, num2)); } else if (choice === '4') { console.log("Result:", divide(num1, num2)); } else if (choice === '5') { console.log("Result:", power(num1, num2)); } } } else { console.log("Invalid input"); } var again = prompt("Do you want to perform another calculation? (yes/no): "); if (again.toLowerCase() !== 'yes') { break; } }