View Single Post
  #1 (permalink)  
Old March 28th, 2005, 05:16 PM
PetraMan PetraMan is offline
Registered User
Join Date: Mar 2005
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Over 21 calculator - project

I am trying to create a JavaScript "over 21 calculator". It's a school project.

I am not understanding how to take User Input Bday and subtract it from my curdate to get the resulting over 21 or not. And then have the script prompt with either Not old enough to drink or Let's party.

I'm a Novice so I'll explain what I want this to do. User clicks on Submit Button, Script prompts for User Input of a Birthday mm/dd/yyyy. Then script takes computer's Current Date and subtracts entered User Bday from Current Date to figure out if they are 21 or not. Then script prompts Lets part or Not old enough.

Yes Mr. MVP I have already looked at the archives and did not find what I need. And I don't know what to look for in the book JavaScript 2nd edition.

Any help would be Greatly Appreciated!! I'm stressing over not knowing.

<TITLE>Legal Drinking Age Meter </TITLE>
 <input type="button" value="Submit" onClick="legalAge()">
<script language="JavaScript" type="text/JavaScript">

var curdate = new Date()
document.write(curdate.getMonth() + 1)
function legalAge()
var ageString;
var legalAge=21;
var ageNum;
       ageString = prompt ("Please enter your age", " ");
       ageNum = parseInt(ageString);
document.write(ageString + "<br>");
if (ageNum >= legalAge)
{alert ("Let's Party!");}
else if (ageNum < legalAge)
{alert ("Sorry! You're too young to drink!");}
else if (ageNum < 0)
{alert ("Please enter a valid age"); }
{alert ("Please enter a valid age"); }


Reply With Quote