Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

dynamic java

Posted on 2011-03-15
9
Medium Priority
?
303 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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:
Gurvinder Pal Singh earned 1000 total points
ID: 35136119
replace line number 18 with

var d = new Date();
year= parseInt(d.getFullYear()) -yeardate;
0
Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

 
LVL 40

Expert Comment

by:Gurvinder Pal Singh
ID: 35136124
i have simply taken the current year from the system date
0
 
LVL 12

Assisted Solution

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

Expert Comment

by:Gurvinder Pal Singh
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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.
Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
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…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

722 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