Solved

dynamic java

Posted on 2011-03-15
9
298 Views
Last Modified: 2012-05-11
hello,

i have this java code it ask for the birthday and gives how old your are, but i want the year to be dynamic so instead of hardcoding the year 2011,  the java shuld ask what year are we now and .....

i have tried everything it's not working

here is my code


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
		<title>3</title>
	</head>
	<body>
		
		<script type="text/javascript">
		name = prompt("your last name");
		
		document.write( "Welkom " + name );
        </script>
		
		<script type="text/javascript">
		fname = prompt("your first name");
		yeardate = parseInt (prompt("give birthday "));
		year= 2011-yeardate
		alert(fname + " , you are " + year + " years!"  );
		
		
		</script>

	</body>
	

</html>

Open in new window

0
Comment
Question by:kensy11
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 35136104
'Not working' means what exactly? It works for me
0
 

Author Comment

by:kensy11
ID: 35136113
this code works but i dont know how to change the hardcoded year 2011 to be dynamic so  the java shuld ask what year are we now and .....
0
 
LVL 40

Accepted Solution

by:
gurvinder372 earned 250 total points
ID: 35136119
replace line number 18 with

var d = new Date();
year= parseInt(d.getFullYear()) -yeardate;
0
 
LVL 40

Expert Comment

by:gurvinder372
ID: 35136124
i have simply taken the current year from the system date
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 12

Assisted Solution

by:enachemc
enachemc earned 250 total points
ID: 35136135
year= new Date().getFullYear()-yeardate
0
 
LVL 40

Expert Comment

by:gurvinder372
ID: 35136138
or else you can use the good old prompt

var currentYear = parseInt(prompt("current year"));
year= currentYear -yeardate;
0
 

Author Comment

by:kensy11
ID: 35136144
thank you
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 35136158
>> but i dont know how to change the hardcoded year 2011 to be dynamic so  

Sorry ;)
0
 
LVL 20

Expert Comment

by:Sathish David Kumar N
ID: 35136170
  yeardate = parseInt (prompt("give birthday "));
alert(yeardate );
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now