Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Ruchit_ECS_30_Calci #340

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Ruchit0812
Copy link

<title>Simple Calculator</title> <style> body { font-family: Arial, sans-serif; display: flex; justify-content: center; align-items: center; height: 100vh; margin: 0; background-color: #f0f0f0; } .calculator { background-color: #fff; padding: 20px; border-radius: 10px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); } .calculator input, .calculator select, .calculator button { width: 100%; margin: 10px 0; padding: 10px; font-size: 16px; border: 1px solid #ccc; border-radius: 5px; } .result { margin-top: 10px; font-weight: bold; } </style>
Add Subtract Multiply Divide Calculate
<script>
    function calculate() {
        // Get the input values
        var num1 = parseFloat(document.getElementById('num1').value);
        var num2 = parseFloat(document.getElementById('num2').value);
        var operation = document.getElementById('operation').value;
        var result;

        // Check if inputs are valid numbers
        if (isNaN(num1) || isNaN(num2)) {
            result = 'Error: Please enter valid numbers';
        } else {
            // Perform the operation based on user selection
            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 = num1 / num2;
                    } else {
                        result = 'Error: Division by zero';
                    }
                    break;
                default:
                    result = 'Invalid operation';
            }
        }

        // Display the result
        document.getElementById('result').innerText = 'Result: ' + result;
    }
</script>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant