JavaScript Coding Challenge - 4

 /*
    Write a program to convert Age to Days (Considering Leap Years)
*/

------------------------------------------------------------------------------------------------

function days(birth_year, current_year){
      let age;
      let leap_years = 0;
      let days;

      if(birth_year<current_year){
         age = (current_year - birth_year);

       if(age<=100){
         for(var i=birth_year; i<current_year; i++){
              if(i%4 ==0 || i%400 ==0){
                   leap_years++;
              }
         }
         leap_years;
         let non_leap_years = (age - leap_years);

          days = ((non_leap_years*365)+(leap_years*366));
          console.log(days);
      }else{
          console.log("Please Enter valid value");
      }
  }
  else{
        console.log("Please Enter Correct value");
  }
}
return days(1992, 2021);

Comments

Popular posts from this blog

Average of All Indexes of Array

JavaScript Coding Challenge-8

Largest and Lowest Number of the Array using JavaScript