+ 1

Making a JS bot that’ll answer questions about a specific topic. need suggestions, advice..

Example: Topic: sololearn. input: how many users on sololearn. And in my JS code I’ll do it like: if (input == “how many users on sololearn || input == “how many users are there on sololearn” || input == “number of users on sololearn” || how many users on SoloLearn” ) {answer = “######} if (input == “who made sololearn” || input == “who created sololearn” || input == “who developed sololearn”) {answer = “name...” } That’s my way. If you have an idea on how to make it easier, please let me know.

5th Aug 2020, 4:42 PM
Ginfio
Ginfio - avatar
6 Respuestas
+ 1
Check this I have tried using regex. https://code.sololearn.com/WGtE4kjlbi30/?ref=app
5th Aug 2020, 6:32 PM
Divya Mohan
Divya Mohan - avatar
+ 1
As you can see I’m using if for every different way of asking the same question. (I could also use switch) So, if you have any ideas, suggestions to simplify the work or amount of code, let me know know. Thank.You()
5th Aug 2020, 4:45 PM
Ginfio
Ginfio - avatar
+ 1
Use regex If question string contain many/number followed by users Ans =##### If question string contain made/created/develop followed by sololearn Ans =name. Hope it will help you.
5th Aug 2020, 4:54 PM
Divya Mohan
Divya Mohan - avatar
+ 1
Divya Mohan thanks, that does help. And what does the regex code look like. use “made”, “created” for example. What does the code look like when put with regex? I’m not very familiar with regex
5th Aug 2020, 4:57 PM
Ginfio
Ginfio - avatar
5th Aug 2020, 4:58 PM
Divya Mohan
Divya Mohan - avatar
+ 1
If you are not the interested in regex. Use .search() method for string to find sub string.
5th Aug 2020, 5:19 PM
Divya Mohan
Divya Mohan - avatar