Chat Bot explainer

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?'
]);
3 Likes

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

7 Likes

Severe neural linguistic programming,

Strange at my solution?

1 Like

Uploading: 2020-12-10 (4).png…
:sweat_smile:

No lo paro de hacer bien pero me dice que esta mal

Hola espero estén bien. Me parece que la explicación se equivoca en esta sección:

Por ejemplo, ‘I love coding’.includes(‘love’) busca el string ‘I love coding’ para el argumento ‘love’. Dado que ‘I love coding’ no contiene ‘love’, todo el comando devuelve true.

Explicación: ‘love’ si está incluido en el string.

En los siguientes niveles el sistema lo explica y adjunto pantallazo.

1 Like

Lol I use my iPad
Qw