Advertisement
iqhtyar2k

ChatBot

Jan 21st, 2024
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.68 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3.  
  4. <head>
  5.     <meta charset="UTF-8">
  6.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7.     <title>AiChatBot</title>
  8.     <style>
  9.         #chat-container {
  10.             max-width: 300px;
  11.             margin: auto;
  12.             border: 1px solid #ccc;
  13.             padding: 10px;
  14.             border-radius: 10px;
  15.         }
  16.     </style>
  17. </head>
  18.  
  19. <body>
  20.     <img src="angeliq.gif" alt="Virtual Girl" width="300">
  21.  
  22.     <p>Mau tanya apa d^_^b:</p>
  23.  
  24.     <input id="input" type="text" placeholder="Type here">
  25.     <button onclick="askQuestion()">Ask</button>
  26.  
  27.     <p id="response"></p>
  28.  
  29.  <script src="jquery.min.js">
  30. </script>
  31.  
  32.     <script>
  33.         // Load data from localStorage
  34.         var storedAnswers = JSON.parse(localStorage.getItem("chatbotAnswers")) || {};
  35.  
  36.         function saveToLocalStorage() {
  37.             localStorage.setItem("chatbotAnswers", JSON.stringify(storedAnswers));
  38.         }
  39.  
  40.         function askQuestion() {
  41.             // get the question from the user
  42.             var question = document.getElementById("input").value;
  43.  
  44.             // your extended AI logic goes here
  45.             if (storedAnswers.hasOwnProperty(question)) {
  46.                 document.getElementById("response").innerHTML = storedAnswers[question];
  47.             } else {
  48.                 var userAnswer = prompt("Maaf, aku enggak mengerti pertanyaan kamu. Aku harus jawab apa ya? :");
  49.                 storedAnswers[question] = "d^_^b  " + userAnswer;
  50.                 document.getElementById("response").innerHTML = storedAnswers[question];
  51.                 // Save updated data to localStorage
  52.                 saveToLocalStorage();
  53.             }
  54.         }
  55.     </script>
  56.  
  57. </body>
  58.  
  59. </html>
  60.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement