dimanche 1 mai 2016

list the leap years using for loop with if statment

i am looking for a way to find the list of leap years between the birthyear and today and print them

function listOfLeapYears(aYear) 
{
aYear = birthDate.getFullYear()
bYear = today.getFullYear()

document.write(aYear + '<br>')
document.write(bYear + '<br>')

    for (i = aYear; i <= bYear; )
    {
        if (isLeapYear(birthDate))
        {
        document.write(i + '<br>');
        }
    birthDate.setFullYear(i+1)

    } 

}


var birthYear, birthMonth, birthDay
    birthYear = parseFloat(window.prompt('please enter your birth year' + ''))
    birthMonth = parseFloat(window.prompt('please enter your birth month' + ''))
    birthDay = parseFloat(window.prompt('please enter your birth day' + ''))

birthDate = new Date(birthYear, birthMonth-1, birthDay)
today = new Date()

document.write('your birth date is ' + dateStringLong(birthDate) + '<br>')
document.write('you are ' + differenceInYears(today, birthDate) + ' years old' + '<br>' )

listOfLeapYears(birthDate)

the for loop with the if statement doesn't seems to work as expected what i want my program to do for example :

birthyear is 1991

today = 2016 is 1991 leap year => yes print it => no move to the next year is 2016 leap yes => yes print it => no stop ( bcuz it is equal to today year )

so any help would be nice

Aucun commentaire:

Enregistrer un commentaire