Solved

dynamic java

Posted on 2011-03-15
9
297 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
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…

758 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

25 Experts available now in Live!

Get 1:1 Help Now