+ 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.
6 Respuestas
+ 1
Check this I have tried using regex.
https://code.sololearn.com/WGtE4kjlbi30/?ref=app
+ 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()
+ 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.
+ 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
+ 1
If you are not the interested in regex. Use .search() method for string to find sub string.