Making a JS bot thatā€™ll answer questions about a specific topic. need suggestions, advice.. | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 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 Respostas
+ 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