Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 307
  • Last Modified:

dynamic java

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
kensy11
Asked:
kensy11
  • 3
  • 2
  • 2
  • +2
2 Solutions
 
CEHJCommented:
'Not working' means what exactly? It works for me
0
 
kensy11Author Commented:
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
 
Gurvinder Pal SinghCommented:
replace line number 18 with

var d = new Date();
year= parseInt(d.getFullYear()) -yeardate;
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
Gurvinder Pal SinghCommented:
i have simply taken the current year from the system date
0
 
enachemcCommented:
year= new Date().getFullYear()-yeardate
0
 
Gurvinder Pal SinghCommented:
or else you can use the good old prompt

var currentYear = parseInt(prompt("current year"));
year= currentYear -yeardate;
0
 
kensy11Author Commented:
thank you
0
 
CEHJCommented:
>> but i dont know how to change the hardcoded year 2011 to be dynamic so  

Sorry ;)
0
 
Sathish David Kumar NCommented:
  yeardate = parseInt (prompt("give birthday "));
alert(yeardate );
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 3
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now