diff --git a/chatbot.js b/chatbot.js index c8242c1..3c9d77e 100644 --- a/chatbot.js +++ b/chatbot.js @@ -55,20 +55,21 @@ function displayBotMessage(message) { chat.scrollTop = chat.scrollHeight; } +// Send the user message and get the bot response // Send the user message and get the bot response async function sendMessage() { let input = document.getElementById("chatbot-input").value; if (input) { displayUserMessage(input); + // Clear the input field immediately after displaying the user message + document.getElementById("chatbot-input").value = ""; + // Wait for the chatbot response - let output = await chatbot(input); // Ensure this line is awaited + let output = await chatbot(input); - setTimeout(function () { - displayBotMessage(output); - }, 1000); - - document.getElementById("chatbot-input").value = ""; + // Display the bot's response + displayBotMessage(output); } } @@ -85,3 +86,5 @@ document sendMessage(); } }); + + diff --git a/index.html b/index.html index 97f2605..b0e00e8 100644 --- a/index.html +++ b/index.html @@ -536,6 +536,23 @@

What type of transportation do you prefer for your travels?

+