Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

123
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!