File size: 744 Bytes
9122591
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<script>
  const chatbotMessages = document.querySelector('.chatbot-messages');
  const chatbotInput = document.querySelector('.chatbot-input input');
  const chatbotButton = document.querySelector('.chatbot-input button');

  chatbotButton.addEventListener('click', () => {
    const userMessage = chatbotInput.value;
    const botMessage = 'Hey alles fresh?';
    const message = `
      <div class="chatbot-message">
        <span class="user">You:</span>
        <span>${userMessage}</span>
      </div>
      <div class="chatbot-message">
        <span class="bot">Bot:</span>
        <span>${botMessage}</span>
      </div>
    `;
    chatbotMessages.insertAdjacentHTML('beforeend', message);
    chatbotInput.value = '';
  });
</script>