Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0613· OpenAIAi2 WildChat-4.8M (AI2)

<!DOCTYPE html> <html> <head> <meta charset="UTF-8"/> <title>Multiplayer Chat…

  1. User

    span { font-weight: bold; }

    .container { width: 300px; margin: 0 auto; }

    input { width: 100%; padding: 10px; margin-bottom: 10px; }

    button { padding: 10px; background-color: #4CAF50; color: white; border: none; cursor: pointer; }

    button:hover { background-color: #45a049; }

    #chat-area { height: 300px; overflow-y: scroll; border: 1px solid black; padding: 10px; }

  2. Assistant

    updateChat() {

    // get the input value var message = document.getElementById("message-input").value;

    // create a new list item var li = document.createElement("li");

    // create a new span element for the message var span = document.createElement("span"); span.textContent = "User: ";

    // create a new text node with the message var messageNode = document.createTextNode(message);

    // append the span and message to the list item li.appendChild(span); li.appendChild(messageNode);

    // append the list item to the chat area document.getElementById("chat-area").appendChild(li);

    // clear the input value document.getElementById("message-input").value = "";

    // scroll to the bottom of the chat area document.getElementById("chat-area").scrollTop = document.getElementById("chat-area").scrollHeight; }

    // add event listener to the send button document.getElementById("send-button").addEventListener("click", updateChat);

    // add event listener to the input field so that pressing enter also triggers the chat update document.getElementById("message-input").addEventListener("keypress", function(event) { if (event.key === "Enter") { event.preventDefault(); updateChat(); } });