Skip to content

Commit 9bcf78a

Browse files
committedJul 25, 2023
chatgpt
1 parent 30dbbbf commit 9bcf78a

File tree

3 files changed

+100
-0
lines changed

3 files changed

+100
-0
lines changed
 

Diff for: ‎Chat gpt/index.html

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<title>Chat Gpt</title>
7+
<link rel="icon" type="image" href="clock.png" />
8+
<link rel="stylesheet" href="style.css" />
9+
</head>
10+
<body>
11+
<div class="chat-container" id="chatContainer">
12+
<!-- chat will here -->
13+
</div>
14+
<div class="input-container">
15+
<input type="text" id="userInput" placeholder="Type your message..." />
16+
<button id="sendButton">Send</button>
17+
</div>
18+
19+
<script src="script.js"></script>
20+
</body>
21+
</html>

Diff for: ‎Chat gpt/script.js

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
const chatContainer = document.getElementById("chatContainer");
2+
const userInput = document.getElementById("userInput");
3+
const sendButton = document.getElementById("sendButton");
4+
5+
const chatbotResponses = [
6+
"Hello! How can I assist you?",
7+
"I'm sorry, I can't answer that question.",
8+
"Please elaborate on your request.",
9+
"That's interesting. Tell me more.",
10+
"I need more information to provide a proper response.",
11+
"How can I help you today?",
12+
];
13+
14+
function displayMessage(sender, message) {
15+
const messageElement = document.createElement("div");
16+
messageElement.classList.add("message");
17+
messageElement.textContent = `${sender}: ${message}`;
18+
chatContainer.appendChild(messageElement);
19+
chatContainer.scrollTop = chatContainer.scrollHeight;
20+
}
21+
22+
function displayChatbotResponse() {
23+
const userMessage = userInput.value.trim();
24+
if (userMessage !== "") {
25+
displayMessage("You", userMessage);
26+
userInput.value = "";
27+
28+
const randomResponse =
29+
chatbotResponses[Math.floor(Math.random() * chatbotResponses.length)];
30+
setTimeout(() => {
31+
displayMessage("ChatGPT", randomResponse);
32+
}, 500);
33+
}
34+
}
35+
36+
sendButton.addEventListener("click", displayChatbotResponse);
37+
userInput.addEventListener("keypress", (event) => {
38+
if (event.key === "Enter") {
39+
displayChatbotResponse();
40+
}
41+
});

Diff for: ‎Chat gpt/style.css

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
body {
2+
font-family: Arial, sans-serif;
3+
margin: 0;
4+
padding: 0;
5+
}
6+
7+
.chat-container {
8+
border: 1px solid #ccc;
9+
border-radius: 5px;
10+
padding: 10px;
11+
height: 300px;
12+
overflow-y: scroll;
13+
}
14+
15+
.input-container {
16+
display: flex;
17+
align-items: center;
18+
padding: 10px;
19+
}
20+
21+
input[type="text"] {
22+
flex: 1;
23+
padding: 5px;
24+
}
25+
26+
button {
27+
margin-left: 10px;
28+
padding: 5px 10px;
29+
background-color: #007bff;
30+
color: #fff;
31+
border: none;
32+
border-radius: 5px;
33+
cursor: pointer;
34+
}
35+
36+
button:hover {
37+
background-color: #0056b3;
38+
}

0 commit comments

Comments
 (0)
Please sign in to comment.