Code Of Chatbot

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background-color: #f0f0f0;
}

.chat-container {
width: 500px;
border: 1px solid #ccc;
border-radius: 5px;
overflow: hidden;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}

.chat-header {
background-color: #85ff00;
color: black;
padding: 10px;
text-align: center;
}

.chat-messages {
padding: 10px;
max-height: 300px;
overflow-y: auto;
}

.chat-input {
display: flex;
padding: 10px;
}

input {
flex: 1;
padding: 5px;
border: 1px solid #ccc;
border-radius: 3px;
}

button {
padding: 5px 10px;
margin-left: 5px;
cursor: pointer;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 9px;
}

.message {
margin-bottom: 10px;
padding: 10px;
border-radius: 5px;
}

.user {
background-color: #e0f7fa;
text-align: right;
}

.bot {
background-color: #c8e6c9;
text-align: left;
}
</style>
<title>Simple Chatbot</title>
</head>
<body>
<div class="chat-container">
<div class="Right-Account" SachinKhanal </div>
<div class="chat-header">
Simple Chatbot
</div>
<div class="chat-messages" id="chatMessages">
<!-- Chat messages will appear here -->
</div>
<div class="chat-input">
<input type="text" id="messageInput" placeholder="Type your message...">
<button onclick="sendMessage()">Send</button>
</div>
</div>

<script>
function sendMessage() {
var messageInput = document.getElementById("messageInput");
var chatMessages = document.getElementById("chatMessages");

var userMessage = messageInput.value;
if (userMessage.trim() === "") {
return;
}

// Display user message
displayMessage(userMessage, "user");

// Simulate chatbot responses based on user's questions
var botMessage;

var lowercaseMessage = userMessage.toLowerCase();

if (lowercaseMessage.includes("how are you")) {
botMessage = "I'm Good How are You";
} else if (lowercaseMessage.includes("joke")) {
botMessage = "Why don't scientists trust atoms? Because they make up everything!";
} else if (lowercaseMessage.includes("namaste")) {
botMessage = "Namaste main yahaan theek hoon aur mujhe aasha hai ki aap vahaan bhee theek honge";
} else if (lowercaseMessage.includes("favorite color")) {
botMessage = "No favorite color for me, but I like all the colors!";
} else if (lowercaseMessage.includes("pets")) {
botMessage = "No pets for me; I'm a virtual assistant.";
} else if (lowercaseMessage.includes("weather")) {
botMessage = "I don't have real-time weather data. Check a weather website for that!";
} else if (lowercaseMessage.includes("recommend a good book")) {
botMessage = "How about 'The Hitchhiker's Guide to the Galaxy' by Douglas Adams?";
} else if (lowercaseMessage.includes("favorite movie")) {
botMessage = "I don't have personal preferences, but 'The Matrix' is a popular choice.";
} else if (lowercaseMessage.includes("favorite actor")) {
botMessage = "I don't have favorites, but many enjoy performances by Meryl Streep.";
} else if (lowercaseMessage.includes("favorite music")) {
botMessage = "I don't have personal taste, but classical music is timeless.";
} else if (lowercaseMessage.includes("sing a song")) {
botMessage = "I'm afraid I can't sing, but I can help with information and tasks!";
} else if (lowercaseMessage.includes("hello")) {
botMessage = "Hello! I'm just a virtual assistant, so I don't have feelings, but I'm here to help.";
} else if (lowercaseMessage.includes("your name")) {
botMessage = "I'm a program, so I don't have a personal name. You can just call me ChatBot!";
} else if (lowercaseMessage.includes("easy to make")) {
botMessage = "If you're into cooking, a simple pasta dish or a sandwich is usually easy to make!";
} else if (lowercaseMessage.includes("favorite food")) {
botMessage = "I don't have personal preferences, but many people enjoy pizza or sushi.";
} else if (lowercaseMessage.includes("nepal")) {
botMessage = "Nepal is a beautiful country in South Asia, known for its stunning landscapes and rich culture.";
} else if (lowercaseMessage.includes("india")) {
botMessage = "India is a diverse country in South Asia, known for its vibrant culture, history, and cuisine.";
} else if (lowercaseMessage.includes("china")) {
botMessage = "China is a vast country in East Asia, known for its ancient civilization, modern cities, and diverse landscapes.";
}
else if (lowercaseMessage.includes("about you")) {
botMessage = "You're Sachin Khanal, A 7th Standard Student Want To Become A Software Engineer In Future";
}
else if (lowercaseMessage.includes("science question 1")) {
botMessage = "Can you name the three states of matter?";
} else if (lowercaseMessage.includes("science question 2")) {
botMessage = "What is the chemical symbol for water?";
} else if (lowercaseMessage.includes("science question 3")) {
botMessage = "Who is known as the father of modern physics?";
} else if (lowercaseMessage.includes("science question 4")) {
botMessage = "What is the powerhouse of the cell?";
} else if (lowercaseMessage.includes("science question 5")) {
botMessage = "What is the largest planet in our solar system?";
} else if (lowercaseMessage.includes("science question 6")) {
botMessage = "What is the process by which plants make their own food?";
} else if (lowercaseMessage.includes("science question 7")) {
botMessage = "What is the speed of light?";
} else if (lowercaseMessage.includes("science question 8")) {
botMessage = "What is Newton's first law of motion?";
} else if (lowercaseMessage.includes("science question 9")) {
botMessage = "Who developed the theory of relativity?";
} else if (lowercaseMessage.includes("about me")) {
botMessage = "You're Sachin Khanal";
}else if (lowercaseMessage.includes("science question 1")) {
botMessage = "Can you name the three states of matter?";
} else if (lowercaseMessage.includes("science question 2")) {
botMessage = "What is the chemical symbol for water?";
} else if (lowercaseMessage.includes("science question 3")) {
botMessage = "Who is known as the father of modern physics?";
} else if (lowercaseMessage.includes("science question 4")) {
botMessage = "What is the powerhouse of the cell?";
} else if (lowercaseMessage.includes("science question 5")) {
botMessage = "What is the largest planet in our solar system?";
} else if (lowercaseMessage.includes("science question 6")) {
botMessage = "What is the process by which plants make their own food?";
} else if (lowercaseMessage.includes("science question 7")) {
botMessage = "What is the speed of light?";
} else if (lowercaseMessage.includes("science question 8")) {
botMessage = "What is Newton's first law of motion?";
} else if (lowercaseMessage.includes("science question 9")) {
botMessage = "Who developed the theory of relativity?";
} else if (lowercaseMessage.includes("science question 10")) {
botMessage = "What is the smallest bone in the human body?";
} else if (lowercaseMessage.includes("science question 11")) {
botMessage = "What is the chemical symbol for gold?";
} else if (lowercaseMessage.includes("science question 12")) {
botMessage = "Who discovered penicillin?";
} else if (lowercaseMessage.includes("science question 13")) {
botMessage = "What is the Earth's outermost layer called?";
} else if (lowercaseMessage.includes("science question 14")) {
botMessage = "Who proposed the theory of evolution by natural selection?";
} else if (lowercaseMessage.includes("science question 15")) {
botMessage = "What is the largest mammal in the world?";
} else if (lowercaseMessage.includes("science question 16")) {
botMessage = "Who is known for the laws of heredity?";
} else if (lowercaseMessage.includes("science question 17")) {
botMessage = "What is the process of converting light into chemical energy in plants?";
} else if (lowercaseMessage.includes("science question 18")) {
botMessage = "What is the chemical formula for table salt?";
} else if (lowercaseMessage.includes("science question 19")) {
botMessage = "Who developed the theory of general relativity?";
} else if (lowercaseMessage.includes("science question 20")) {
botMessage = "What is the center of an atom called?";
} else if (lowercaseMessage.includes("worst country")) {
botMessage = "According To Me, North Korea is worst country";
} else if (lowercaseMessage.includes("god real")) {
botMessage = "As An Chatbot i didn't say about that god Is Real Or Just Thinking";
} else if (lowercaseMessage.includes("best blog website")) {
botMessage = "https://sachinkhanal1.blogspot.com is best blog website powered by blogger";
} else if (lowercaseMessage.includes("i am also fine")) {
botMessage = "Feeling Good To Hear That";
} else if (lowercaseMessage.includes("best company")) {
botMessage = "AOOA Is The Best Company";
} else if (lowercaseMessage.includes("i love you")) {
botMessage = "Ohh! but sorry i like myself than you";
} else {
botMessage = "Sorry Sachin, I Don't Know About That";
}

// Display chatbot message
displayMessage(botMessage, "bot");

// Clear the input field
messageInput.value = "";
}

function displayMessage(message, sender) {
var chatMessages = document.getElementById("chatMessages");

var messageElement = document.createElement("div");
messageElement.classList.add("message", sender);
messageElement.innerHTML = message;

chatMessages.appendChild(messageElement);

// Scroll to the bottom to show the latest message
chatMessages.scrollTop = chatMessages.scrollHeight;
}

function loadChatHistory() {
chatHistory.forEach((entry) => {
displayMessage(entry.message, entry.sender);
});
}

// Call loadChatHistory on page load
window.onload = loadChatHistory;
</script>
</body>
</html>

Comments