document.addEventListener("DOMContentLoaded", () => { const sendButton =…
- User
document.addEventListener("DOMContentLoaded", () => { const sendButton = document.querySelector(".send-button"); const inputField = document.querySelector(".input-field"); const messagesSection = document.querySelector(".messages-section");
// Send message handler sendButton.addEventListener("click", () => { if (!inputField.value.trim()) return;
code// Create outgoing message bubble const messageBubble = document.createElement("div"); messageBubble.classList.add("chat-bubble", "outgoing"); messageBubble.innerHTML = <p>${inputField.value}</p> <span class="timestamp">${new Date().toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })}</span> ; messagesSection.appendChild(messageBubble); inputField.value = ""; // Auto-scroll to bottom messagesSection.scrollTop = messagesSection.scrollHeight; // Add subtle animation messageBubble.style.opacity = "0"; setTimeout(() => (messageBubble.style.opacity = "1"), 10);}); }); fix code, error in line 14
- Assistant
The code in line 14 has an issue because the
innerHTMLproperty is incorrectly assigning a template literal (which should be a string) directly as if it were JavaScript code. The proper way to assign this content is by wrapping the HTML markup in a string.Here's the corrected version of your code:
javascript