...

View Full Version : Why won't this work



rsines
03-15-2005, 04:02 PM
<script language="Javascript">
function test()
{var today = new Date();
mo = today.getMonth();
yr = today.getFullYear();
if (yr = 2006)
document.write(mo);
if (yr = 2005)
document.write(yr)};
</script>

afru
03-15-2005, 04:14 PM
Hi,

Checkout code below....


var today = new Date();
var mo = today.getMonth();
var yr = today.getYear();

if (yr == "2006")
document.write(mo);
if (yr == "2005")
document.write(yr);


By the way the answer will always be 2005 becuase present year is 2005.

Have a nice day :)

Afru.

Kor
03-15-2005, 05:39 PM
Nope, getFullYear() is a valid method. The errors lays only in the bitwise comparation

if (yr == 2006){
document.write(mo);}
if (yr == 2005){
document.write(yr);}

getYear() might return '05' in Moz or similar;



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum