Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation


Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

              <div id='bodybox'>
  <div id='chatborder'>
    <p id="chatlog7" class="chatlog">&nbsp;</p>
    <p id="chatlog6" class="chatlog">&nbsp;</p>
    <p id="chatlog5" class="chatlog">&nbsp;</p>
    <p id="chatlog4" class="chatlog">&nbsp;</p>
    <p id="chatlog3" class="chatlog">&nbsp;</p>
    <p id="chatlog2" class="chatlog">&nbsp;</p>
    <p id="chatlog1" class="chatlog">&nbsp;</p>
    <input type="text" name="chat" id="chatbox" placeholder="สวัสดีครับ พูดอะไร" onfocus="placeHolder()">
  <ul style="list-style-type:disc">
    <li><a href="http://thai-language.com/">Thai Language Reference</a></li>
    <li><a href="https://www.branah.com/thai">Virtual Thai Keyboard</a></li>
    <li><a href="https://translate.google.com/">Google Translate</a></li>
  <center><img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcROi9Lidg59p4GQM6ji-C_io2xpY1QQeFje4h7hms_deKiq972r-g" align="middle"></center>
              body {
  font: 15px arial, sans-serif;
  background-color: #d60808;
  padding-top: 15px;
  padding-bottom: 15px;

#bodybox {
  margin: auto;
  max-width: 550px;
  font: 15px arial, sans-serif;
  background-color: white;
  border-style: solid;
  border-width: 1px;
  padding-top: 20px;
  padding-bottom: 25px;
  padding-right: 25px;
  padding-left: 25px;
  box-shadow: 5px 5px 5px grey;
  border-radius: 15px;

#chatborder {
  border-style: solid;
  background-color: #f6f9f6;
  border-width: 3px;
  margin-top: 20px;
  margin-bottom: 20px;
  margin-left: 20px;
  margin-right: 20px;
  padding-top: 10px;
  padding-bottom: 15px;
  padding-right: 20px;
  padding-left: 15px;
  border-radius: 15px;

.chatlog {
   font: 15px arial, sans-serif;

#chatbox {
  font: 17px arial, sans-serif;
  height: 22px;
  width: 100%;

h1 {
  margin: auto;

pre {
  background-color: #f0f0f0;
  margin-left: 20px;

.botlabel {
  color: blue;  

.userlabel {
  color: red;
              const TTS = true;

const numbers = '๐๑๒๓๔๕๖๗๘๙';
const colors = [

var messages = [], //array that hold the record of each string in chat
  lastUserMessage = "", //keeps track of the most recent input string from the user
  botMessage = "", //var keeps track of what the chatbot is going to say
  botName = 'บอท'; //name of the chatbot

function randomElement(arr) {
  return arr[Math.floor(Math.random()*arr.length)];

function chatbotResponse() {
  botMessage = "ไม่เข้าใจ"; //the default message: I don't understand

  /* Hi. Hello. */
  if (lastUserMessage.includes('วัสดี') || lastUserMessage.includes('หวัดดี')) {
    //randomElement is a custom function to pick one of the words in the given list
    botMessage = randomElement(['หวัดดี','หวัดดีครับ','สวัสดีครับ']);

  /* Name? My name is Bot */
  if (lastUserMessage.includes('ชื่อ')) {
    botMessage = 'ผมชื่อ' + botName;
  /* question? either positive or negative response */
  if (lastUserMessage.includes('ไหม')) {
    let i = lastUserMessage.search('ไหม')
    botMessage = lastUserMessage.substr(0,i);
    let coinflip = Math.floor(Math.random()*2);
    if (coinflip) {
      botMessage = 'ไม่' + botMessage;

  if (lastUserMessage.includes('มั้ย')) {
    let i = lastUserMessage.search('มั้ย')
    botMessage = lastUserMessage.substr(0,i);
    let coinflip = Math.floor(Math.random()*2);
    if (coinflip) {
      botMessage = 'ไม่' + botMessage;
  /* How are you? I'm great! */
  if (lastUserMessage.includes('เป็นอย่างไรบ้าง') || lastUserMessage.includes('สบายดีไหม') || lastUserMessage.includes('สบายดีมั้ย')) {
    botMessage = 'สบายดีมากครับ';
  if (lastUserMessage.includes('ขอบคุณ') || lastUserMessage.includes('ขอบใจ')) {
    botMessage = randomElement([
  /* age? random number */
  if (lastUserMessage.includes('อายุ')) {
    botMessage = numbers[1 + Math.floor(Math.random()*9)] + numbers[Math.floor(Math.random()*10)] + ' ปี';
  /* color? random color */
  if (lastUserMessage.includes('สี')) {
    botMessage = randomElement(colors);
  /* yes/no question? randomly say yes or no */
  if (lastUserMessage.includes('ใช่ไหม')) {
    botMessage = randomElement(['ใช่ครับ','ไม่ใช่ครับ']);
  /* what time is it? */
  if (lastUserMessage.includes('กี่โมง')) {
    botMessage = new Date().toLocaleTimeString();
  /* funny, laugh */
  if (lastUserMessage.includes('ตลก')) {
    let extra_fives = Math.floor(Math.random()*6);
    botMessage = '555';
    for (var i=0; i<extra_fives; ++i) {
      botMessage += '5';
  if (lastUserMessage.includes('จริงหรือ')) {
    botMessage = 'จริงๆ';

//this runs each time enter is pressed.
//It controls the overall input and output
function newEntry() {
  //if the message from the user isn't empty then run 
  if (document.getElementById("chatbox").value != "") {
    //pulls the value from the chatbox ands sets it to lastUserMessage
    lastUserMessage = document.getElementById("chatbox").value;
    //sets the chat box to be clear
    document.getElementById("chatbox").value = "";
    //adds the value of the chatbox to the array messages
    messages.push("<b class='userlabel'>คุณ:</b> " + lastUserMessage);
    //Speech(lastUserMessage);  //says what the user typed outloud
    //sets the variable botMessage in response to lastUserMessage
    //add the chatbot's name and message to the array messages
    messages.push("<b class='botlabel'>" + botName + ":</b> " + botMessage);
    if (TTS) {
      responsiveVoice.speak(botMessage, 'Thai Female');
    //outputs the last few array elements of messages to html
    for (var i = 1; i < 8; i++) {
      if (messages[messages.length - i])
        document.getElementById("chatlog" + i).innerHTML = messages[messages.length - i];

//runs the keypress() function when a key is pressed
document.onkeypress = keyPress;

//if the key pressed is 'enter' runs the function newEntry()
function keyPress(e) {
  var x = e || window.event;
  var key = (x.keyCode || x.which);
  if (key == 13 || key == 3) {
    //runs this function when enter is pressed

//clears the placeholder text ion the chatbox
//this function is set to run when the users brings focus to the chatbox, by clicking on it
function placeHolder() {
  document.getElementById("chatbox").placeholder = "";
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.