JSFiddle - React, Tailwind, and code Playground

by frogggeee McFrogggeee

HTML

<html>
<head>
<body style = "text-align: left">
<h1>self-learning chat bot</h1>
<p>by buttersam</p>
<br>
<input type="text" id="in">
<button onclick = "refresh()">enter</button>
<br>
<p id = "info"></p>
<p id = "chat"></p>
<script>
let nextAns = 'norm';
let lastAns = "";
let answer = 0;
let pressed = 0;
let text = "<b>Dimblo: </b>hello, im dimblo, the AI." + "<br>" + "<b>Dimblo: </b>talk to me to help me learn" + "<br>";
document.getElementById("chat").innerHTML = text;
let words = ["hello"];
let answers = ["hi!~hi~hello there~hello~"];
function refresh() {
 answer = document.getElementById("in").value;
 text = text + "<b>you: </b>" + answer + "<br>";
 lastAns = answer;
 document.getElementById("in").value = "";
 document.getElementById("chat").innerHTML = text;
 
    //// part where dimblo answers ////
 if (nextAns == "norm") {
 if (words.includes(answer) == false) {
  text = text + "<div style = "text-align: center"><b>MESSAGE: </b>" + "the AI does not know that word. please type what YOU would say in response." + "<br></div>";
  words.push(answer);
  answers.push("");
  text = text + "<b>Dimblo: </b>" + answer + "<br>";
  lastAns = answer;
  nextAns = 'learn';
  
 } else {
  let ans = [];
  let wor = " ";
  //if (Math.floor(Math.random() * 2) == 0) {}
   //answers.splice(words.indexOf(answer), 1, answers[words.indexOf(answer)] + "~" + answer);
   // doesn't work for some reason. this is for expanding its responses to that word.*/
  for (let i = 0; i < answers[words.indexOf(answer)].length; i++) {
   if (answers[words.indexOf(answer)].charAt(i) != "~") {
    wor += "" + answers[words.indexOf(answer)].charAt(i);
   } else {
    ans.push(wor);
    wor = "";
	
   }
  }
  let sayy = ans[Math.floor(Math.random() * ans.length)];
  text = text + "<b>Dimblo: </b>" + sayy + "<br>";
  lastAns = sayy;
  //answers.splice(words.indexOf(answer), 1, answers[words.indexOf(answer)] + "~" + answer);
 }
 } else if (nextAns == 'learn') {
  answers.splice(words.indexOf(answer), 1,...