Basic Chatbot Code-Along

For this exercise, start by forking this empty Repl.

Then, follow along with the instructor to build a little text-based JavaScript program. The program will prompt the user with a question and will then reply back with an alert message containing the user's answer.

Create the JavaScript File

In the Files section on the left, click the New file button. Give the new file a name of script.js.

Within the script.js file, add a statement that will show a welcome message to the user.

alert("Welcome to the chatbot!");
  1. In the index.html, add a <head></head> element
  2. Within the <head></head> element, add a <script></script> element
  3. Add a src attribute to the <script> opening tag to point to the script.js file
<html>
    <head>
        <script src="script.js"></script>
    </head>
</html>

Run the webpage, and make sure the alert() pop-up with the message appears!

Note: a <body></body> is not required for this HTML page.

Ask a Question

Ask the user for their name and show a text box to the user allowing them to type their answer. Be sure to choose a descriptive variable name to store this value!

let username = prompt("What's your name?");

Display a Reply

Show the user a formatted message containing their name.

alert("Cool! I love the name '" + username + "'. I think it means 'smart.'");

results matching ""

    No results matching ""