+ 2

I guess I didn't think about this problem... do you think there's a way to fix this

In this code I'm trying to make a bot that will answer your questions. I've already done some work to it, and I came across a problem so I just made a snippet so you are not overwhelmed looking at the whole code. input = "this is my question"; the input is your question. Ask anything there. The Problem: q1 = "hi" q2 = "ship" The bot will Test things like this; if (input is "hi") {answer = "hello, how are you"} else if (input is "ship"){ answer = "no, we don't have any ships"} You see the problem there: hi, and s__hi__p. The bot will always thinks it's hi, because it's dumb, you know what i mean_!!. That's just how it is. I don't know how to make it smarter so it can identify two different words. https://code.sololearn.com/W12sn4v66HzX/#js experiment with the code to better understand.

21st Sep 2020, 1:48 AM
Ginfio
Ginfio - avatar
2 Answers
+ 3
You could use word boundaries: https://javascript.info/regexp-boundary /\bhi\b/i will match: "hi" //true "ship" //false "a b c d hi e f" //true
21st Sep 2020, 8:13 AM
Kevin ★
+ 3
Kevin ★ Thank You So Much! After looking at the site on the link you sent me, it didn't take long for me to fix the code. Thx. Again.
21st Sep 2020, 1:24 PM
Ginfio
Ginfio - avatar