Solved

dynamic java

Posted on 2011-03-15
9
299 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
LVL 40

Expert Comment

by:gurvinder372
ID: 35136124
i have simply taken the current year from the system date
0
 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

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.
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

776 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