Click to See Complete Forum and Search --> : uni example :( i cant do


lisa_anne
01-05-2003, 10:42 AM
hey, im new hre and ive just started java at uni and im a little stuck. can someone hlp me figure out how to do this please?





Using JavaScript, write an html document that prompts the user for his/her age.

If the user is under 18, bring up an alert box saying the user is too young.
If the user is between 18 and 70, bring up an alert box saying the user is old enough to enter the site.
If the user is over 70, bring up an alert box saying the user is too old to proceed.


thank you:)
lisa

khalidali63
01-05-2003, 11:23 AM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>Untitled</title>
<script>
window.onload=userInfo;

function userInfo(){
var input = prompt("Pleae enter your age.","");
if(!isNaN(input) && parseInt(input)>0){
var age = parseInt(input);
if(age<18){
alert("You are too young to view this web site.Waite few yrs and then come back.");
}//put other else if (condition) statement for rest of your tasks
//th reason I have not done all of it for you is that it will lose any purpose of
//teaching.Just follow the pattern above and see whats happening and try to make rest
//of your conditions work
}else{
alert("Please enter a number 1 and above.")
}
}
</script>
</head>

<body>

David Harrison
01-05-2003, 11:27 AM
OK the code is:

<html>

<head>

<script language="javascript">

var age = ''
age=prompt('How old are you?','');

if(age < 18){location.href="yourtooyoung.html";}
else if(age > 17 && age < 71){location.href="okyourein.html";}
else if(age > 70){location.href="yourtooold.html";}
else{location.href="youdidntenteryourage.html";}

</script>

</head>

<body>
</body>

</html>

And the attachment is a zipped copy of the webpage.

If you want to read the source of that or alter it, you'll have to open it in a text document.

lisa_anne
01-05-2003, 12:11 PM
thank u for all ur help, im getting it working, just on prob. how do i do from 18 to 70 u can enter, i cant figure out how to do that part

David Harrison
01-05-2003, 12:51 PM
just have the page that's restricted as a different page, using my script that would be okyourein.html