Chat Bot explainer


#1

Aim of the puzzle: Use the .includes() method to check if a string is part of another string.

Walk through of solution: The 1st if statement checks if the chat variable has the string ‘hello’ in it. The 2nd if statement checks if the entire value of chat is equal to ‘bye’ but it should check if part of the string is a match.

Remove ‘bye’ and the === inside the 2nd if statement’s test () so only chat is in the parentheses. Tap chat inside the 2nd if statement. Now tap the .includes() button to attach the method to the chat variable. Inside the .includes() add the string ‘bye’. Your chat bot can now respond to a greeting or a farewell message in the chat.

Sample code solution:
(Tap below to reveal)

print(chat);

if (chat.includes('hello')) {
    print('Hi, can I help you pick a destination?');
}
if (chat.includes('bye')) {
    print('See you later, have a great trip!');
}

Javascript Concepts: Variables, Strings, If Statements, .includes()

Grasshopper Concepts: print()

Additional Code (hidden code that runs before the puzzle’s code):

var chat = pickRandom([
  'hello I need some help', 
  'Thanks, bye', 
  'hello', 
  'goodbye', 
  'kthnxbye', 
  'umm, hello?'
]);

#4

This puzzle is really amazing, now I get it how those customer support chat bot replys :grin: :v:t3: