It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming JavaScript Forum

Newbie to Java Script I am trying to understand this?? Help!

Newbie to Java Script I am trying to understand this?? Help!

Postby nerdherd on Sat Sep 13, 2008 1:11 pm

This is the Hint: you need to find that and then read the script very carefully, now in this script, it uses the getYear() function, instead of the getFullYear() function, this is a very bad idea because ever since the milenium getYear has messed up, e.g: in 1984 getYear would print out 84 and in 1999 it would print out 99, but ever since 2000 it started to go above 99 and carry on counting into 100s. From that you should be able to work it out.

a = prompt("Please enter password!","");
date = new Date();
year = date.getYear();
b = year+12;
if(a == b){
alert("Good job! You got it!");
window.location.href=year+".php";
}
else
{
alert("Try it again!");

}


Your help would be most appreciated thnx
User avatar
nerdherd
 
Posts: 3
Joined: Sat Sep 13, 2008 1:08 pm
Location: North Pole with Santa

Postby flabbyrabbit on Sat Sep 13, 2008 8:14 pm

Are you trying to find out the answer? What site is this from?

If you are trying to work this out the easiest way to do it, is to:
Code: Select all
<script type="text/javascript">
//a = prompt("Please enter password!","");
date = new Date();
year = date.getYear();
b = year+12;
alert(b);
if(a == b){
alert("Good job! You got it!");
window.location.href=year+".php";
}
else
{
alert("Try it again!");
}
</script>
The // Comments out the password alert so it doesn't show up. The alert(b); will show what b is. If you copy and paste this into notepad, save it as a .html file and open it in FF/IE. A pop up will come up showing the answer (120).

But simply is is the year (as explained in the hint). 2008 = 108. So year+12=120, as simple as that!

Flabby Rabbit
Image
User avatar
flabbyrabbit
500+ Club
 
Posts: 706
Joined: Thu Jan 25, 2007 1:10 pm
Location: Midlands, England

Postby rangana on Sun Sep 14, 2008 3:08 am

Don't use get.Year(), use get.FullYear().

For further reading
http://cf-bill.blogspot.com/2007/11/jav ... lyear.html
User avatar
rangana
500+ Club
 
Posts: 935
Joined: Wed Feb 27, 2008 5:14 am
Location: Cebu City Philippines

Postby flabbyrabbit on Sun Sep 14, 2008 11:15 am

He wasn't writing the script he was doing something that involved him working out what the script did.

Flabby Rabbit
Image
User avatar
flabbyrabbit
500+ Club
 
Posts: 706
Joined: Thu Jan 25, 2007 1:10 pm
Location: Midlands, England

Postby rangana on Mon Sep 15, 2008 5:51 am

Mind rephrasing it Flabby, I'm confused. Was the response addressed to me or to the OP?
User avatar
rangana
500+ Club
 
Posts: 935
Joined: Wed Feb 27, 2008 5:14 am
Location: Cebu City Philippines

Postby flabbyrabbit on Mon Sep 15, 2008 10:30 am

You, the OP didn't write the code so he doesn't need to be corrected.

Flabby Rabbit
Image
User avatar
flabbyrabbit
500+ Club
 
Posts: 706
Joined: Thu Jan 25, 2007 1:10 pm
Location: Midlands, England

Postby rangana on Tue Sep 16, 2008 2:03 am

Okay, so then you need to be corrected. Never use getYear().

Hope that makes sense.
User avatar
rangana
500+ Club
 
Posts: 935
Joined: Wed Feb 27, 2008 5:14 am
Location: Cebu City Philippines


Who is online

Users browsing this forum: No registered users and 5 guests