Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

124
Vistas
react question using javascript leap year in react

trying to figure out how to create a leap year program I created most of it but so far the if statements are not working properly so just trying to figure out why it is not working

import "./App.css";
import leapyear from "./images/leapyear.jpeg";
import React, { useState } from "react";

function App() {
  const [year, setYear] = useState(" ");

  const handleClick = (e) => {
    e.preventDefault();

  if(( 0 == e%4) && ( 0 != e%100 ) && (0 == e%400)){
    console.log('it is a leap year')
  }
  else{
    console.log('it is not a leap year')
  }
}

  return (
    <div className="app">
      <h1>Leap Number Calculator</h1>
      <img className="leapimg" src={leapyear}></img>
      <form onSubmit={handleClick}>
        <label>Enter a year and we will see if it is a leap year</label>
        <input
          type="text"
          value={year}
          onChange={(e) => setYear(e.target.value)}
        ></input>
        <input type="submit"></input>
      </form>
    </div>
  );
}

export default App;
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

It's not working because your formula for checking if the year is leap is wrong.

function isLeapYear(year) {
  return year % 400 === 0 || (year % 100 !== 0 && year % 4 === 0);
}

To determine if a year is leap, it has to be either:

  • dividable by 400
  • dividable by 4 but not by 100

See wikipedia: https://en.wikipedia.org/wiki/Leap_year

about 4 years ago · Juan Pablo Isaza Denunciar

0

const year = 2024

const isLeapYear = (year) => {
  return (year % 100 === 0) ? ( year % 400 === 0) : (year % 4 === 0);
}

if (isLeapyear(year)) console.log('yeah')
if (!isLeapyear(year)) console.log('no')
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda