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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource


Babel includes JSX processing.

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


Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.


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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.


                <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="">Thai Language Reference</a></li>
    <li><a href="">Virtual Thai Keyboard</a></li>
    <li><a href="">Google Translate</a></li>
  <center><img src="" 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 ='ไหม')
    botMessage = lastUserMessage.substr(0,i);
    let coinflip = Math.floor(Math.random()*2);
    if (coinflip) {
      botMessage = 'ไม่' + botMessage;

  if (lastUserMessage.includes('มั้ย')) {
    let i ='มั้ย')
    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 = "";