Load the text file,
How much tuition?
About $50
Around fifty dollars
How are you?
I am fine,tks !
You are beautiful!
Thank you very much!
So are you
What day is today?
Today,Monday
Tomorrow Tuesday
I am not sure about today
... into an array:
var script = [
[
"HOW MUCH TUITION",
"About $50",
"Around fifty dollars",
],
[
"HOW ARE YOU",
"I am fine,tks !",
],
[
"YOU ARE BEAUTIFUL",
"Thank you very much!",
"So are you",
],
[
"WHAT DAY IS TODAY",
"Today,Monday ",
"Tomorrow Tuesday",
"I am not sure about today",
],
];
console.log(script[0][0]); // How much tuition?
The first element (uppercase) in the array is always key zero and always the “Q” which is matched.
And the remaining elements are 1,2,3, etc count can vary in the array and they are always the “R” list.
You can randomly pick one from the “R” list for a response.
Please note: This code is hand coded in a text editor and is not tested at all, and it is not complete, so it is just for discussion and learning purposes. As a Node.JS programmer, you should be inspired from this pseudo code.