🚀 Basics Day 7: In-Class Exercises 🚀

Pre-Class In-Class

Base: Chat Bot Single Chat Bot Answer Set

Implement the chat bot that asks a yes/no/maybe question and can respond to a user's response of "yes", "no", or "maybe".


Input:


Output:

Base: Chat Bot Multiple Chat Bot Answer Sets

Extend the capabilities of the chat bot by storing question and answer text in the same object.

To have our chat bot support more than 1 question, put the questionAndAnswerSet object into an array of chat bot answer sets, and add a 2nd answer set to our array. The bot will pick which question to ask and answer next.

Implement a chat bot that alternates between these 2 questions.


Input:


Output:

Base: Chat Bot Stores User's Name

Add a new chat bot question that asks for the user's name and responds with a sentence containing the user's name. After greeting the user, the chat bot proceeds with the question from previous exercises.

Use the user's name in the bot's subsequent output. You may want to store the user name in a global variable.


Input:


Output:

Base: Chat Bot Stores User's Age

Update the chat bot to ask for the user's age after their name. The chat bot's response will differ based on the user's age. For example, we can respond with different outputs if the user is under 20, between 20-60, and above 60.


Input:


Output:

More Comfortable: Chat Bot Named Answer Sets

Update our chat bot answer set array to be an object whose keys are answer set IDs and values are answer sets. Also add a nextQuestion key to each answer set object, whose value is always an answer set ID, enabling us to chain question sequences in a named manner. This doesn't add new functionality beyond ordering questions using an array, but it sets up the next exercise Dynamic Chat Bot.


Input:


Output:

More Comfortable: Dynamic Chat Bot

Update our chat bot to choose a next question based on the answer that the user gives. This next question's ID can be stored in the object that corresponds to the user's answer. See the following sample answer set collection for inspiration. Note that some questions have nextQuestionId nested within specific answers, and other question have nextQuestionId fixed for the question.


Input:


Output:

More Comfortable: Chat Bot Fortune Telling

Add questions to our chat bot that are purportedly for fortune telling, but where the bot always provides standard responses that anyone might believe are individualised. For example, the bot might ask "Let me tell your fortune. If you have a birthmark, where is it on your body?" and respond with "You have a great need for other people to like and admire you."


Input:


Output: