...

View Full Version : Loop



midsmanuk
07-08-2007, 10:05 AM
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>

midsmanuk
07-08-2007, 10:23 AM
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>

Philip M
07-08-2007, 11:13 AM
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.

midsmanuk
07-08-2007, 10:20 PM
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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum