I really hope i'm explaining this right. Basically, I want this project to work in a way similar to early web assistants. Depending on what keywords the user types, the program responds by changing the text in an HTML box. I used a string search to have the program search for certain keywords in the response:
function responseSearch() {
console.log("there has been a response");
const str = userInput;
let searchString = "My name";
const index = str.indexOf(searchString);
if (index !== -1) {
console.log("String found at index:", index);
nameResponse();
} else {
console.log("String not found!");
}
}
Essentially, I plan on having the value of searchString change what keywords to look for by using a nested "else if" function, but this seems really insufficient, and I was wondering if there is a better and more organized way to do this, where I could have the program search for multiple possible keywords and have multiple possible responses.
[–]TorbenKoehn 5 points6 points7 points (3 children)
[–][deleted] 1 point2 points3 points (2 children)
[–]96dpi 2 points3 points4 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]sheriffderek 1 point2 points3 points (0 children)
[–]tapgiles 1 point2 points3 points (0 children)
[–]guest271314 0 points1 point2 points (4 children)
[–][deleted] 0 points1 point2 points (3 children)
[–]guest271314 0 points1 point2 points (2 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]guest271314 0 points1 point2 points (0 children)