codex-lv2-may-2025

Level Navigation: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 Current Level: 20 21 22 23 24 25 26 27 28 29 30 31 32


đź§Ş Level 20: Add State for Input

What You’ll Do

Create a variable to store the user’s input.

Instructions

Create a global variable for the user’s text (e.g., let userPrompt = "";).

đź’ˇ Code Hints

Storing user input? You’ll need a variable to hold what the user types. Check out the Variables section in SNIPPETS.md for variable declaration examples.

âś… Check

  1. Open your webpage in a browser
  2. Open Chrome DevTools (F12) and go to the Console tab
  3. Type userPrompt and press Enter
  4. You should see an empty string "" or whatever value you assigned
  5. If you get an error like “userPrompt is not defined”, check that you declared the variable in your chatbot.js file
  6. Make sure the variable is declared at the top level (not inside a function)

Next: Level 21 - Capture Input on Click



Level Navigation: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 Current Level: 20 21 22 23 24 25 26 27 28 29 30 31 32