Home
Manage Your Code
Snippet: Birthday Generator - Javascript (JavaScript)
Title: Birthday Generator - Javascript Language: JavaScript
Description: This simple script will generate birthday day/month/year. All the data is stored into variable which could be used wherever you want. Views: 242
Author: Stoyan Borisov Date Added: 6/16/2012
Copy Code  
//************************************************************
// Generates Birthday Day/Month/Year                         *
// There's no check for the day/month relationship,          *
// so the birthday can't be 29,39,31                         *
// to prevent nonsense like 31.02 (February 31th)            *
//************************************************************
function bnum (min, max) {
    return Math.floor(Math.random() * (max - min + 1)) + min;
}
var bday=bnum(1,29)
var bmonth=bnum(1,12)
var byear=bnum(1980, 1995)
alert(bday);
alert(bmonth);
alert(byear);
Usage
You can use the variables bday, bmonth, byear in your code as you see fit.

To remove the promopts, just remove:
alert(bday);
alert(bmonth);
alert(byear);