Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (9.5k points)

Here’s my code implementation:

<script>

function monthassign()

{

    document.getElementById("month").selectedIndex=0;

}

function isleap()

{

    var yr=document.getElementById("year").value;

    if ((parseInt(yr)%4) == 0)

    {

      if (parseInt(yr)%100 == 0)

      {

        if (parseInt(yr)%400 != 0)

        {

        //alert("Not Leap");

        return "false";

        }

        if (parseInt(yr)%400 == 0)

        {

        //alert("Leap");

        return "true";

        }

      }

      if (parseInt(yr)%100 != 0)

      {

        //alert("Leap");

        return "true";

      }

    }

    if ((parseInt(yr)%4) != 0)

    {

        //alert("Not Leap");

        return "false";

    } 

}

function dateassign()

{

    var yr=isleap();

    var mth=parseInt(document.getElementById("month").selectedIndex);

    var dt=document.getElementById("date")

    if(yr)

    {

        if(mth==2)

        {   

            //alert(yr);

            dt.options.length = 0;

            for(i=1; i<30; i++)

            {   

                dt.add(new Option(i,i), null) //add new option to end of "date"

            }

            return;

        }

    }

    if(yr==false && mth==2)

    {

        //alert("Second fun");

        dt.options.length = 0;

        for(i=1; i<29; i++)

        {   

            dt.add(new Option(i,i), null) //add new option to end of "date"

        }

        return; 

    }

    if(mth==4 || mth==6 || mth==9 || mth==11)

    {

        dt.options.length = 0;

        for(i=1; i<31; i++)

        {   

            dt.add(new Option(i,i), null) //add new option to end of "date"

        }

        return; 

    }

    else

    {

        dt.options.length = 0;

        for(i=1; i<32; i++)

        {   

            dt.add(new Option(i,i), null) //add new option to end of "date"

        }

        return; 

    }

}   

</script>

When variable yr contains false, it’s expected to shift the program control to the code block if(yr==false && mth==2). But my program is not getting into the if block when the condition is false. Can anyone tell me how to do it? 

1 Answer

0 votes
by (19.7k points)

When you write “true” and “false” like this, it’ll be taken as a string. So in order to write Boolean values, you need to replace them with just true and false. 

Interested in Java? Check out this Java Certification by Intellipaat.   

Browse Categories

...