Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4

Thread: Loop

  1. #1
    New Coder
    Join Date
    Jun 2007
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Loop

    Why does this code not run

    <HTML>
    <HEAD>
    <TITLE>mikes test</TITLE>
    </HEAD>
    <BODY>


    /* Program which uses a while loop to display a calendar for a given year */

    //Write your code below:

    var year= parseFloat(window.prompt('Enter Year',"));

    var date = newDate(year, 0);

    for (var month = 0; month<12; month = month + 1)

    {

    date.set Month(month); // update the month

    displayMonth(date) // display the calendar for that month

    }


    </BODY>
    </HTML>

  • #2
    New Coder
    Join Date
    Jun 2007
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I have tried this but get an error on the parseFloat command any ideas


    <HTML>
    <HEAD>
    <TITLE> mikes test</TITLE>
    <SCRIPT SRC=dateLibrary.js> </SCRIPT>
    <SCRIPT>


    /* Program which uses a while loop to display a calendar for a given year */

    //Write your code below:

    var year= parseFloat(window.prompt('Enter Year', "));

    var date = newDate(year, 0);

    for (var month = 0; month<12; month = month + 1)

    {

    date.set Month(month); // update the month

    displayMonth(date) // display the calendar for that month

    }

    </SCRIPT>
    </HEAD>
    <BODY>
    </BODY>
    </HTML>

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,899
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Change:- var year= parseFloat(window.prompt('Enter Year', "));

    to

    var year= parseFloat(window.prompt('Enter Year', ""),10);

    What if the user enters something which is not a valid number?

    See posting guidelines re homework assignments and silly thread titles.
    Last edited by Philip M; 07-08-2007 at 11:17 AM.

  • #4
    New Coder
    Join Date
    Jun 2007
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for your help just want to reassure you it is not homework or an assignment it is an activity within a course book which i am struggling to understand.

    Mike


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •