I have the following array in a chatbot
This piece of code searches the first part of the array and triggers the second part as a response. That all works fine. However, could it be rewritten in a way to eliminate the bailout response of "I don't know. Perhaps you can look it up on a map." to where it just skips over it if no match is found.Code:Sites=new Array("alcatraz,California in the USA","eiffel tower,Paris in France","empire state building,New York in the USA","grand canyon,Arizona in the USA","leaning tower of pisa,Pisa in Italy");
I have more If statements further down the script that I want to use instead of the one bailout response. If nothing matches I have one big catchall to respond back with at the very end.
Code:if (input.search("where is")!= -1) {document.result.result.value = "I don't know. Perhaps you can look it up on a map."; for (i=0; i<Sites.length; i++) { Site=Sites[i].split(','); if (input.search(Site[0]) != -1) { document.result.result.value = Site[1];} } return true;}



Reply With Quote

Bookmarks