-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
46 lines (39 loc) · 1.64 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
document.getElementById("sendButton").addEventListener("click", sendMessage);
document.getElementById("userInput").addEventListener("keypress", function(event) {
if (event.key === 'Enter') {
sendMessage();
}
});
function sendMessage() {
const userMessage = document.getElementById("userInput").value.trim();
if (userMessage) {
// Display user's message
addMessage("You", userMessage);
// Clear input field
document.getElementById("userInput").value = "";
// Simulate a system response
setTimeout(() => {
addMessage("Opponent", getSystemResponse());
}, 1000); // Wait for 1 second before responding
}
}
function addMessage(sender, message) {
const messageContainer = document.getElementById("messages");
const messageElement = document.createElement("div");
messageElement.classList.add("message");
messageElement.textContent = `${sender}: ${message}`;
messageContainer.appendChild(messageElement);
messageContainer.scrollTop = messageContainer.scrollHeight; // Auto-scroll to bottom
}
function getSystemResponse() {
// Array of sample responses for the opponent
const responses = [
"I understand your point, but here is why I disagree...",
"That's an interesting perspective. However, research shows...",
"I see where you're coming from, but have you considered...",
"I respectfully disagree because...",
"Your argument is valid, but here’s an opposing viewpoint...",
];
// Randomly select a response
return responses[Math.floor(Math.random() * responses.length)];
}