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

kensy11Asked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
Gurvinder Pal SinghConnect With a Mentor Commented:
replace line number 18 with

var d = new Date();
year= parseInt(d.getFullYear()) -yeardate;
0
 
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
What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

 
Gurvinder Pal SinghCommented:
i have simply taken the current year from the system date
0
 
enachemcConnect With a Mentor Commented:
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 NArchitectCommented:
  yeardate = parseInt (prompt("give birthday "));
alert(yeardate );
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.