samedi 2 septembre 2017

else if statements not firing beyond first iteration

I am trying to use if and else statements to display pictures based upon the season.
For var currentMonth = new Date().getMonth(); it returns the current month as 0-11 0 being Jan and 11 being Dec. Now I am fairly sure that my problem lays within how I am executing the else if statements. When I change my desktop date it will only display the image for winter or for spring no matter the month I use. It displays the winter picture when it should but the spring image will display during all other months. That says to me that its an issue with the else if statements. Any help would be much appreciated

    <script language="javascript">

    function retrievePictures(){
    var currentMonth = new Date().getMonth();


    if(currentMonth >= 10 || currentMonth <=1){
    //winter
        var html = '<img src="img/hall-of-gods.jpg" width="600" height="400" alt="Hall Of The Gods" />';

    }

  else if(currentMonth >= 2 || currentMonth <=4){
    //spring
        var html = '<img src="img/merlyn.jpg" width="600" height="400" alt="Spring Time Cat" />';

    }

    else if(currentMonth >= 5 || currentMonth <=7){
    //summer    
        var html = '<img src="img/bounty.jpg" alt="Summer Bounty" width="600" height="400" />';

    }

 else{
    //autum    
        var html = '<img src="img/louis.jpg" alt="King Louis" width="600" height="400" />';

    }
        document.write(html);
    }
    </script>



    <div class="slideshow">
        <script type="text/javascript">
            retrievePictures();
        </script>

Aucun commentaire:

Enregistrer un commentaire