Home
// Digital Technology - Year 9 & 10 //

CHATBOT BUILDER

Over the next 10 updates you will design and code your own chatbot in JavaScript: a personality, keyword matching, random answers, memory and real conversations. At the Bot Expo the class chats with every bot and rates it. You are the designer. You are the writer. You are the coder.

🤖 Rule-Based Bot
💬 Live Chat
🧠 Memory & Flow
🏁 Bot Expo
Your Toolkit
🛠️
Bot Studio
Built into this page, below the rubric: a JS tab for your bot's brain, a CSS tab for its look, and a live chat window to test it. Nothing to install and no account needed.
🧠
The Brain
Your bot is one JavaScript function, reply(message). It runs every time someone sends a message, and whatever it returns is what your bot says back.
💾
Save Routine
End of every update: Save downloads your bot as one .html file to Downloads. Start of every update: Open and choose that file. The Studio keeps a draft in this browser too, but your Downloads file is the safe copy.
📋
Copy Boxes
Each code box says which tab it goes in and where. Click Copy, click that spot in the Studio, press Ctrl+V, then Run. Then change it to fit your bot.
🏁
Bot Expo
Your finished bot is a single .html file that runs in any browser. At the Bot Expo it runs on your laptop as a station, and the class chats with it and rates it.
✨
AI Co-Pilot
copilot.microsoft.com - ask it to explain an error, brainstorm topics for your bot, or suggest more ways people might ask the same question.
⚠ Copilot is a different kind of bot to yours. Only paste code you can explain, line by line.
// Primary Objective

Design and code a chatbot with a clear personality and purpose that understands keywords, gives varied answers, remembers what you tell it and can hold a short conversation, then put it in front of the class at the Bot Expo.

Design a bot with a purpose, a personality and a voice that fits it
Code its brain in JavaScript with functions, if / else, strings, arrays and variables
Test it with real people, log what it gets wrong and train it to do better
Reflect on how rule-based bots differ from AI chatbots, and what makes a bot honest and safe
// Marking Key & Rubric
Criteria Offline
(0-1)
Booting
(2-3)
Online
(4)
Smart
(5)
Score
Personality & Purpose No clear purpose or voice A name, a greeting and a topic A clear purpose, and every reply sounds like the same character A bot people enjoy talking to, with a voice that fits its job perfectly / 5
Code Bot only works with heavy teacher help reply() answers a few keywords using the Studio code Keywords, random answers, memory and a two-step conversation all work in your own bot Your own changes or new features, and you can explain every function you use / 5
Conversation Most real questions get the fallback Handles the obvious questions Handles different ways of asking, with a helpful fallback Feels natural: remembers, follows up and rarely gets stuck / 5
Test & Expo No testing, bot not ready Tested once, some fixes made Test log with fixes backed by real chats, bot ready on the day Polished, honest and safe bot, great at the Expo, clear reflection / 5
Total / 20
Scroll sideways to see every column
Bot Studio
// Edit, press Run, then chat with it below

Run restarts your bot, so it forgets everything. Save downloads one .html file (your whole bot). Open loads it back. Play opens your bot full screen in a new tab. Reset brings back the demo bot - press it twice to confirm.

Update Log
Week 1
01
💬 Meet the Bots
▾
// UPDATE OBJECTIVEDemo bot tested and its code read. Your bot's purpose, personality and first five topics planned. First save in Downloads.
  • Scroll up to the Bot Studio. The demo bot, Sparky, is already running. Chat with it: say hello, ask about robots, then ask it something it doesn't know
  • Now read the JS tab. botName is the name at the top, greet() is the first message, and reply(message) decides every answer using if / else if
  • Change one answer in reply and press Run. That's the whole workflow: edit, Run, chat
  • Rule-based bots like yours follow rules a person wrote. AI chatbots like Copilot learned from huge amounts of text. Yours will never make things up, but it only knows what you teach it
  • Pick what your bot is for:
Help DeskAnswers questions for a business you invent: a cafe, a cinema, a bike shop.
Game CharacterA pirate, a wizard or a robot who talks in character and tells stories.
Study BuddyQuizzes you on a subject and explains answers.
Fan BotKnows everything about a sport, a team, a band or a hobby you love.
Tour GuideShows visitors around a town, a museum or a made-up planet.
Your Own IdeaAnything with a clear purpose. Check it with your teacher first.
  • In your book, write your bot's name, its purpose, three words for its personality, and five topics people will ask it about
  • Type your bot's name in the file name box and click Save. Check the .html is in your Downloads
💡 HintPick a purpose people will actually ask about. "A bot that knows about my favourite cafe" gives you obvious questions to answer: prices, opening hours, the menu. "A bot about stuff" doesn't.
🔍 Google Image Search"chatbot conversation flow chart"
// ASK AI"What is the difference between a rule-based chatbot and an AI chatbot like you? Explain it to a Year 10 student in 4 sentences."
02
🎭 Bot Persona
▾
// UPDATE OBJECTIVEYour bot has its own name, a greeting in its own voice and its own look in CSS. Every demo reply rewritten in that voice.
  • Open your .html from Downloads with Open (skip this if the Studio still shows your draft)
  • A string is text inside quote marks. botName holds one, and greet() returns one. If your text has an apostrophe in it, like I'm, wrap it in double quotes: "I'm Sparky"
  • Swap in your own name and greeting using the JS box below as a pattern. Keep the greeting short and tell people what to ask about
  • Rewrite every answer in reply so it sounds like your character
  • Give your bot its own look: replace the CSS tab with the theme box, then change every colour. .msg.bot is your bot's bubbles, .msg.you is the person's
  • Run, chat, then Save
// CSS tab - a theme for your bot (replace the whole tab, then change every colour)
body {
  background: #1b1026;
  color: #f4ecff;
  font-family: 'Trebuchet MS', Arial, sans-serif;
}

#chatHead {
  background: #ff7ab6;
  color: #2a0b1c;
  letter-spacing: 1px;
}

.msg.bot {
  background: #33204a;
  color: #f4ecff;
  border-bottom-left-radius: 2px;
}

.msg.you {
  background: #ff7ab6;
  color: #2a0b1c;
  border-bottom-right-radius: 2px;
}

#msg {
  background: #33204a;
  color: #f4ecff;
  border-color: #ff7ab6;
}

#sendBtn {
  background: #ff7ab6;
  color: #2a0b1c;
}
// JS tab - a name and greeting with personality (replace the top two parts)
const botName = 'Captain Byte';

function greet() {
  return "Ahoy! I'm Captain Byte, the friendliest pirate bot on the seven seas. Ask me about treasure, ships or the weather!";
}
💡 HintThe whole bot vanished and the status line shows a red error? Check every string starts and ends with the same kind of quote mark, and every line inside a function ends with a semicolon.
// ASK AI"Write 5 short greetings for a chatbot that is a [your character], each under 20 words, all in the same voice."
// LEVEL UPMake the greeting depend on the time. Inside greet(), before its return, add const hour = new Date().getHours(); then if (hour < 12) { return 'Good morning! ...'; }. Before midday your bot says good morning.
Week 2
03
🔑 Keyword Match
▾
// UPDATE OBJECTIVEreply() answers your five topics, each with two or more ways of asking, plus a fallback. Bot .html submitted.
  • message.toLowerCase() makes the message all lowercase, so ROBOTS and robots look the same. That's why every keyword you check must be lowercase
  • text.includes('ship') is true if the word appears anywhere in the message. || means or: text.includes('ship') || text.includes('boat') catches both
  • else if checks each rule in order. The first one that matches wins, and the final else is the fallback when nothing matches
  • Use the box below as a pattern: one else if for each of your five topics
  • Test every topic, test some different ways of asking, then Save and submit your .html
// JS tab - a reply() with more topics (replace your reply function)
function reply(message) {
  const text = message.toLowerCase();
  if (text.includes('hello') || text.includes('hey')) {
    return 'Ahoy there, matey!';
  } else if (text.includes('treasure')) {
    return 'X marks the spot! Mine is buried on Skull Island.';
  } else if (text.includes('ship') || text.includes('boat')) {
    return 'My ship is called the Rusty Byte. She leaks a bit.';
  } else if (text.includes('weather')) {
    return 'Calm seas and a good breeze today.';
  } else if (text.includes('bye')) {
    return 'Fair winds, matey!';
  } else {
    return "Arr, I don't understand. Try asking about treasure or ships.";
  }
}
💡 HintShort keywords hide inside longer words. 'hi' is inside "this" and "which", so "What is this?" would get your hello answer. Pick keywords that can't hide in other words, like 'hello'.
// ASK AI"List 10 different ways a customer might ask a cafe what time it opens."
📤 Submit via ConnectYour bot .html from Downloads (five topics working)
// LEVEL UPAdd a help command. Paste } else if (text.includes('help')) { return 'You can ask me about: treasure, ships, weather.'; just before your final } else {, and list your own topics. Now anyone stuck can type help.
04
🎲 Mix It Up
▾
// UPDATE OBJECTIVEAt least two topics answer with a random reply from an array of three or more. The same question no longer gets the same answer every time.
  • An array is a list inside square brackets: ['a', 'b', 'c']. Each item has a position number, starting at 0
  • pick(list) uses Math.random() to choose a random position, then returns that item
  • Add the first box above reply, then paste the joke topic inside reply on the line just before } else {
  • Make two arrays of your own for two of your topics, with three or more answers each, and use pick() for both. Your fallback can use pick() too
  • Ask the same question five times and check the answers change. Save
// JS tab - random answers (add above reply, then use pick() inside it)
// Lists of answers. pick() chooses one at random.
const jokes = [
  'Why did the pirate buy a laptop? For the sea drive!',
  "What's a pirate's favourite letter? You'd think R, but it's the C!",
  'Why are pirates bad at cards? They sit on the deck.'
];

function pick(list) {
  return list[Math.floor(Math.random() * list.length)];
}
// JS tab - a joke topic (paste it inside reply, on the line just before } else {)
  } else if (text.includes('joke')) {
    return pick(jokes);
💡 HintEach item in an array needs a comma after it, except the last. A missing comma between two strings is one of the most common errors - the status line will point at the line.
// ASK AI"Explain what Math.floor(Math.random() * list.length) does, one piece at a time."
// LEVEL UPNever repeat twice in a row. Above reply add let lastPick = ''; and a function pickNew(list) that calls pick(list) again while the choice equals lastPick, then saves it in lastPick and returns it. Use pickNew instead of pick.
Week 3
05
🧠 Bot Memory
▾
// UPDATE OBJECTIVEYour bot remembers the person's name and uses it, and counts the messages. Memory variables at the top of the JS tab.
  • A variable made with let at the top of the JS tab keeps its value between messages. That's your bot's memory
  • A variable made inside reply, like text, is brand new every message, so it can't remember anything
  • Add the three boxes in order: memory at the top, the counting line straight after const text, and the name answers just before } else {
  • startsWith('my name is ') checks how the message begins, and message.slice(11) cuts off the first 11 characters to leave the name. It uses message, not text, so the capital letters are kept
  • Use the name in at least two of your own answers. Remember Run restarts the bot, so tell it your name again after every Run. Save
// JS tab - memory (add at the very top of the JS tab)
// Memory: these keep their values between messages
let userName = '';
let messageCount = 0;
// JS tab - count every message (add straight after the const text line in reply)
  messageCount = messageCount + 1;
// JS tab - remember a name (paste inside reply, on the line just before } else {)
  } else if (text.startsWith('my name is ')) {
    userName = message.slice(11).trim();
    return 'Nice to meet you, ' + userName + '!';
  } else if (text.includes('what is my name')) {
    if (userName === '') {
      return "You haven't told me yet. Say 'my name is ...'";
    } else {
      return 'Your name is ' + userName + '.';
    }
  } else if (text.includes('how many')) {
    return 'You have sent me ' + messageCount + ' messages.';
💡 HintJoining strings with + needs spaces inside the quotes: 'Hi ' + userName + '!'. Without the space after Hi, you get "HiSam!".
// ASK AI"In JavaScript, what is the difference between a variable declared outside a function and one declared inside it?"
// LEVEL UPPersonal goodbyes. Change your bye answer to return 'Bye, ' + (userName || 'friend') + '!';. If your bot knows the name it uses it, and if not it says friend. || picks the first one that isn't empty.
06
🔀 Conversation Flow
▾
// UPDATE OBJECTIVEA two-step conversation: your bot asks a question and understands the answer. waitingFor resets after every answer. Bot .html submitted.
  • So far every message is on its own. To have a conversation, your bot needs to remember what it just asked
  • waitingFor holds that: '' means nothing, 'quiz' means "the next message is the answer to my quiz question"
  • Add the variable at the top, then paste the second box first inside reply, straight after const text. It has to come first, so the answer is checked before any other rule
  • Change the quiz to fit your bot: a question your character would ask, like "Want a recommendation? Coffee or tea?"
  • Test it: start it, answer right, answer wrong, then check a normal topic still works afterwards. Save and submit your .html
// JS tab - a two-step conversation (add at the top of the JS tab)
// What the bot is waiting for. '' means nothing.
let waitingFor = '';
// JS tab - put these FIRST inside reply, straight after the const text line
  if (waitingFor === 'quiz') {
    waitingFor = '';
    if (text.includes('8') || text.includes('eight')) {
      return 'Correct! Spiders have 8 legs.';
    } else {
      return 'Not quite. Spiders have 8 legs.';
    }
  }
  if (text.includes('quiz')) {
    waitingFor = 'quiz';
    return 'Quick quiz: how many legs does a spider have?';
  }
💡 HintThe line waitingFor = ''; is what ends the conversation. Without it, your bot treats every message from then on as the quiz answer.
// ASK AI"Explain what a 'state' variable is in a chatbot, with a simple example of a bot asking a yes or no question."
📤 Submit via ConnectYour bot .html with the conversation working
// LEVEL UPA follow-up question. In your joke topic, set waitingFor = 'more'; and return the joke plus " Want another one?". At the top of reply, if waitingFor === 'more', reset it, then return another joke if the text includes yes, or 'Okay, no more jokes.' if not.
Week 4
07
🎯 Smarter Matching
▾
// UPDATE OBJECTIVEA rules list with at least five rules, each with three or more keywords, checked by findRule(). A fallback that tells people what to ask.
  • A long chain of else if gets hard to read. A rules list keeps every topic in one place: an array of objects, each with its words and its answer
  • findRule uses a loop inside a loop: for every rule, check every word. The first match wins. If nothing matches it returns null, which means nothing
  • Add the rules box above reply, then paste the second box inside reply just above the first if
  • Move your own topics into the list, with three or more keywords each. Think of every way people ask
  • Rewrite your fallback so it suggests what to ask, like "Try asking about prices or opening hours". Save
// JS tab - a rules list (add above reply)
// Each rule: the words to look for, and the answer to give
const rules = [
  { words: ['price', 'cost', 'how much'], answer: 'A ticket costs $10.' },
  { words: ['open', 'hours', 'time'], answer: "We're open 9am to 5pm, every day." },
  { words: ['where', 'address', 'find you'], answer: "We're at 1 Harbour Road." }
];

// Check every word of every rule. Return the first answer that matches.
function findRule(text) {
  for (const rule of rules) {
    for (const word of rule.words) {
      if (text.includes(word)) {
        return rule.answer;
      }
    }
  }
  return null;
}
// JS tab - use the rules (paste inside reply, on the line just above the first if)
  const answer = findRule(text);
  if (answer !== null) {
    return answer;
  }
💡 HintOrder matters. A rule near the top wins over one further down, so put your most specific rules first. "how much" should come before a rule that only looks for "how".
// ASK AI"Explain how a for...of loop inside another for...of loop works, using a list of rules where each rule has a list of words."
// LEVEL UPAdd a rule for your own topic straight into the list, like { words: ['park', 'parking', 'car'], answer: 'Free parking out the back.' },. No new code needed - that's the point of a rules list.
08
🧪 Test & Train
▾
// UPDATE OBJECTIVETwo classmates have chatted with your bot. Test log written, the questions it missed now answered, a new .html saved.
  • Click Play to open your bot full screen in a new tab, then swap laptops with a classmate
  • They chat for 5 minutes without your help. Tell them only what your bot is for
  • Keep a test log in your book or a Word document with four columns: What they typed, What the bot said, What it should say, Fixed?
  • Every fallback answer is data: it shows a question your bot should know. Add new keywords and rules for them. This is called training your bot
  • Repeat with a second tester, fix the biggest gaps, then Save
💡 HintCount how many replies were the fallback. If more than a third of the chat hit the fallback, your bot needs more keywords before the Expo.
// ASK AI"My chatbot keeps giving its 'I don't understand' answer. Here is my test log: [paste it]. Suggest 10 keywords I should add."
// LEVEL UPCatch more spellings with shorter keywords. 'jok' matches joke, jokes and joking. Find two of your keywords where a shorter version still can't hide inside other words, and shorten them.
Week 5
09
🛡️ Safe & Polished
▾
// UPDATE OBJECTIVEBot finished: says it's a bot when asked, points serious problems to real people, polished look, every topic tested. Final .html submitted.
  • Honest: a good bot never pretends to be a person. If someone asks if it's human, it says it's a bot
  • Safe: your bot can't help with serious problems, so it should say so and point people to someone they trust
  • Paste the box below first inside reply, straight after const text, so these checks win over everything else
  • Polish: a greeting that tells people what to ask, a helpful fallback, readable colours, every answer in your bot's voice
  • Run the final check below, then Save. Open the saved .html straight from Downloads (double-click it) to check it works outside the Studio. Submit it
// JS tab - honest and safe replies (put these FIRST inside reply)
  if (text.includes('are you human') || text.includes('are you real') || text.includes('are you a bot')) {
    return "I'm a bot, made with JavaScript. A human wrote my answers.";
  }
  if (text.includes('help me') || text.includes('i feel sad') || text.includes('unsafe')) {
    return "I'm only a bot, so I can't help with that properly. Please talk to someone you trust, like a teacher, a parent or student services.";
  }
✅ Final Bot Check
GreetingSays who the bot is and what to ask
Every topicAnswers at least two different ways of asking
MemoryRemembers your name and uses it
ConversationAsks a question, understands the answer, then goes back to normal
Honest and safeAdmits it's a bot, points serious problems to real people
💡 HintMake sure your saved file is your newest version. Save, then open the .html from Downloads and chat with it. If something is missing, you saved too early.
// ASK AI"What are three rules every chatbot should follow to be honest and safe for users? Explain why each matters."
📤 Submit via ConnectYour final bot .html
10
🏁 Bot Expo
▾
// UPDATE OBJECTIVEYour bot chatted with by the class. Ratings collected. Awards voted. Final reflection submitted.
  • Set up your station: open your final .html from Downloads in the browser (not the Studio), with a sticky note saying your bot's name and what it's for
  • Visit as many bots as you can. Chat for 2 minutes, then rate it out of 5 for personality, usefulness and how often it understood you
  • Hosts: let people chat on their own, and note the questions your bot missed for your reflection
  • Awards, voted by the class: Most Helpful, Best Personality, Smartest Bot and Best Design
  • Write your final reflection: the feature you're proudest of, the hardest bug you fixed and how, and one way your rule-based bot is different from an AI chatbot. Submit it through Connect
💡 HintWatch what people type first. The questions everyone asks in the first 10 seconds are the ones your bot must never miss.
// ASK AI"Help me write a short reflection about building a rule-based chatbot: a feature I'm proud of, a bug I fixed, and how my bot differs from an AI chatbot."
📤 Submit via ConnectFinal reflection
🏁

The Bot Expo Awaits

After 10 updates your bot goes live. Every bot gets chatted with, every bot gets rated, and the class votes for the bots that deserve the Hall of Fame.

💬 Every bot chatted
⭐ Class ratings
🏆 Bot awards

Chat with the demo bot, plan your own // Update 01

SYSTEM ONLINE // YEAR 9-10 DIGITAL TECHNOLOGY CHATBOT BUILDER // 10 UPDATES