javascript code for age calculator chatbot

Solutions on MaxInterview for javascript code for age calculator chatbot by the best coders in the world

showing results for - "javascript code for age calculator chatbot"
Simone
16 Jan 2020
1
2var year;
3var month;
4var day;
5var today = new Date();
6
7console.log(Date());
8Bot.send("Enter the year in which you were born");
9var state = year;
10async function respond(inputText) {
11	if (state == year) {
12		year = inputText;
13		Bot.send("Enter the month in which you were born");
14		state = month;
15	}
16	else if (state == month) {
17		month = inputText;
18		Bot.send("Enter the day");
19		state = day;
20	}
21	else if (state == day) {
22		day = inputText;
23		if (month < today.getMonth()) {
24			var age = today.getFullYear() - year;
25			Bot.send("Your age is" + age);
26		}
27		else if (month > today.getMonth()) {
28			var age = today.getFullYear() - year - 1;
29			Bot.send("Your age is" + age);
30		}
31		else {
32			if (day > today.getDay) {
33				var age = today.getFullYear() - year - 1;
34				Bot.send("Your age is " + age);
35			}
36			else {
37				var age = today.getFullYear() - year;
38				Bot.send("Your age is" + age);
39				state = year;
40			}
41		}
42	}
43
44}