Skip to content

*Operaciones aritméticas* #1

@DEIVIMH7

Description

@DEIVIMH7
<title>OPERACIONES ARITMÉTICAS</title> <style> .title-box { border: 2px solid red; background-color: white; text-align: center; padding: 15px; margin-bottom: 20px; font-weight: bold; font-size: 1.5em; } .btn-blue { background-color: #007bff; color: white; } .btn-blue:hover { background-color: #0056b3; } .btn-link-blue { color: #007bff; font-size: 1.1em; } .btn-link-blue:hover { text-decoration: underline; } input[type="number"] { border: 2px solid #007bff; border-radius: 5px; padding: 10px; background-color: white; font-size: 1em; } input[type="number"]:focus { outline: none; box-shadow: 0 0 5px #007bff; } .result { font-size: 1.5em; color: #343a40; margin-top: 15px; text-align: center; } </style>
OPERACIONES ARITMÉTICAS
Primer Número:
Segundo Número:
Tercer Número:
SUMA RESTA MULTIPLICACIÓN DIVISIÓN
<!-- Bootstrap JS Bundle -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.1/dist/js/bootstrap.bundle.min.js"></script>
<script>
    function calculate(operation) {
        const num1 = parseFloat(document.getElementById('num1').value);
        const num2 = parseFloat(document.getElementById('num2').value);
        const num3 = parseFloat(document.getElementById('num3').value);
        let result;

        if (isNaN(num1) || isNaN(num2)) {
            document.getElementById('result').innerText = 'Por favor, ingrese al menos dos números válidos.';
            return;
        }

        switch (operation) {
            case 'sum':
                result = num1 + num2 + (isNaN(num3) ? 0 : num3);
                break;
            case 'subtract':
                result = num1 - num2 - (isNaN(num3) ? 0 : num3);
                break;
            case 'multiply':
                result = num1 * num2 * (isNaN(num3) ? 1 : num3);
                break;
            case 'divide':
                if (num2 === 0 || (operation === 'divide' && num3 === 0)) {
                    document.getElementById('result').innerText = 'No se puede dividir por cero.';
                    return;
                }
                result = num3 ? num1 / num2 / num3 : num1 / num2;
                break;
            default:
                result = 'Operación no válida.';
        }

        document.getElementById('result').innerText = `Resultado: ${result}`;
    }
</script>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions