I understand but that is the challenge of making a chatterbot is processing natural language. I'm just not a programmer but enjoy creating the responses and the like. But bare with me if you will. 
I have a script now that gives:
current day = tellTheDay()
curent month = tellTheMonth()
current year = tellTheYear()
I came up with this if only a year is given. I can't give exact date without month and day but close.
Code:
if ((input.search("i was born")!= -1) && (input.search(/\b(19[0-9]{2}|200[0-9]|201[01])\b/)!= -1) || (input.search("how old am i")!= -1)) {
var myMatch = input.match(/\b(19[0-9]{2}|200[0-9]|201[01])\b/);
var age = (tellTheYear() - myMatch[0]);
document.result.result.value = "You're approximate age is "+age+".";
return true;}
I can pull out the month if it's spelled out like Jan, Feb, March etc. and I can pull the day by setting a range of 1 to 31. I know there are a lot of other combination that will pop up but that's something I can work on down the road.
What I can't do is figure how to use the day, month and year and come up with the exact age.
This script does the calculations but I'm not sure how to use it in the bot.
Code:
function getAge(year, month, day) {
var now = new Date();
var today =
{
"year" : now.getFullYear(),
"month": now.getMonth()+1,
"day" : now.getDate()
}
var age = today["year"] - year;
if(month > today["month"])
age--;
else if(month == today["month"])
if(day > today["day"]) age--
return age;
}
Bookmarks