1
resposta

Função que determine se um ano é bissexto

HTML (PEDIR PARA O CHATGPT APENAS FAZER O HTML

<!DOCTYPE html>
<html lang="pt-BR">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Verificador de Ano Bissexto</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f4f4f9;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
        }

        .container {
            background-color: #ffffff;
            padding: 2rem;
            border-radius: 10px;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
            text-align: center;
            max-width: 400px;
            width: 100%;
        }

        h1 {
            color: #333;
            margin-bottom: 1.5rem;
            font-size: 2rem;
        }

        label {
            font-size: 1rem;
            color: #555;
        }

        input[type="number"] {
            width: 100%;
            padding: 0.75rem;
            margin: 1rem 0;
            border: 1px solid #ccc;
            border-radius: 5px;
            font-size: 1rem;
        }

        button {
            background-color: #007bff;
            color: white;
            border: none;
            padding: 0.75rem 1.5rem;
            border-radius: 5px;
            font-size: 1rem;
            cursor: pointer;
            transition: background-color 0.3s ease;
        }

        button:hover {
            background-color: #0056b3;
        }

        #resultado {
            margin-top: 1.5rem;
            font-size: 1.2rem;
            color: #333;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>Verificador de Ano Bissexto</h1>
        <form id="anoForm">
            <label for="ano">Digite um ano:</label>
            <input type="number" id="ano" name="ano" required placeholder="Ex: 2024">
        </form>
        <button onclick="verificar()">Verificar</button>
        <p id="resultado"></p>
    </div>

    <script src="app.js"> </script>
</body>
</html>

JAVASCRIPT

function verificar () {
    let ano = parseInt(document.getElementById('ano').value);
    let txtResult = document.getElementById('resultado');
    let calculo = ano / 4;
    if (Number.isInteger(calculo) == true)  {
        txtResult.innerHTML  = `O ano ${ano} é bissexto`;
    } else {
        txtResult.innerHTML  = `O ano ${ano} não é bissexto`;
    }
}
1 resposta

Oi João, tudo bem? 😊

Seu HTML está bem estruturado e estilizado! 👍

No entanto, a lógica para determinar se um ano é bissexto precisa de alguns ajustes. 🤔 A regra geral é que um ano é bissexto se for divisível por 4, exceto os anos que são divisíveis por 100, a menos que sejam divisíveis por 400.

Aqui está o código JavaScript corrigido:

function verificar() {
    let ano = parseInt(document.getElementById('ano').value);
    let txtResult = document.getElementById('resultado');

    if ((ano % 4 === 0 && ano % 100 !== 0) || ano % 400 === 0) {
        txtResult.innerHTML = `O ano ${ano} é bissexto`;
    } else {
        txtResult.innerHTML = `O ano ${ano} não é bissexto`;
    }
}

🎓 Para saber mais:

Espero ter ajudado e bons estudos! 🧐