JS qna bot code help | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

JS qna bot code help

I'm trying to make a JS qna bot that answers questions about a specific topic. I'm trying to get it to check for a possible question keyword, In this example: Keywords: how many beans | number of beans // line 53 If user enters one of the above, Answer = "800 beans" // line 108 var PQ1 = /how many beans|number of beans/; var PA1 = PQ1.test(input.toLowerCase()); switch (input.toLowerCase()){ case PA1: Ans = "800 beans"; break; } The problem is it doesn't work. Cuz PA1 returns a value of true (or 1). Instead of the string that is found in PQ1. https://code.sololearn.com/Wi4hy9HIJ3nc/#js

10th Aug 2020, 3:27 PM
Ginfio
Ginfio - avatar
4 Answers
+ 1
Ginfio I have a bot code where I check text in input and then respond accordingly . Check if it helps. https://code.sololearn.com/WxuNmwss4QWD/?ref=app
13th Aug 2020, 9:31 AM
Divya Mohan
Divya Mohan - avatar
+ 1
If you win PA1 to hold the string of PQ1, why are you using test?
10th Aug 2020, 9:25 PM
JME
+ 1
JME wait, wut? PA1 // possible answer 1, is testing if any of the steings in PQ1 match the input value.
10th Aug 2020, 11:29 PM
Ginfio
Ginfio - avatar
+ 1
Divya Mohan It does help. Thank u so much.
13th Aug 2020, 9:14 PM
Ginfio
Ginfio - avatar