0% found this document useful (0 votes)
132 views9 pages

AI Chatbot HTML Code Example

The document is an HTML code for a Creative AI Chatbot interface that allows users to interact with a chatbot through a chatbox. It includes styling for the chat interface and JavaScript functions to handle user input, simulate bot responses, and display messages. The bot can respond to various user prompts with predefined responses, making the chat experience engaging and interactive.

Uploaded by

geethasb1980
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
132 views9 pages

AI Chatbot HTML Code Example

The document is an HTML code for a Creative AI Chatbot interface that allows users to interact with a chatbot through a chatbox. It includes styling for the chat interface and JavaScript functions to handle user input, simulate bot responses, and display messages. The bot can respond to various user prompts with predefined responses, making the chat experience engaging and interactive.

Uploaded by

geethasb1980
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd

<!

DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,
initial-scale=1.0">
<title>Creative AI Chatbot</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
padding: 20px;
}
#chatbox {
width: 100%;
max-width: 600px;
height: 400px;
border: 1px solid #ccc;
overflow-y: auto;
padding: 10px;
background: white;
margin-bottom: 10px;
}
#userInput {
width: calc(100% - 90px);
padding: 10px;
}
#sendBtn {
padding: 10px;
}
.message {
margin: 10px 0;
}
.user {
color: blue;
text-align: right;
}
.bot {
color: green;
text-align: left;
}
</style>
</head>
<body>

<h1>Creative Chatbot</h1>
<div id="chatbox"></div>
<input type="text" id="userInput" placeholder="Type your
message...">
<button id="sendBtn">Send</button>

<script>
const chatbox = [Link]('chatbox');
const userInput = [Link]('userInput');
const sendBtn = [Link]('sendBtn');
[Link]('click', sendMessage);
[Link]('keypress', function (e) {
if ([Link] === 'Enter') {
sendMessage();
}
});

function sendMessage() {
const userMessage = [Link]();
if (userMessage === '') return;

appendMessage(userMessage, 'user');
[Link] = '';

// Simulate a bot response


setTimeout(() => {
const botResponse = getBotResponse(userMessage);
appendMessage(botResponse, 'bot');
}, 500);
}

function appendMessage(message, sender) {


const messageDiv = [Link]('div');
[Link]('message', sender);
[Link] = message;
[Link](messageDiv);
[Link] = [Link]; // Scroll to the
bottom
}

function getBotResponse(userMessage) {
// Responses without punctuation
const responses = {
'hello': 'Hey there! Ready to chat?',
'hi': 'Hi! What is buzzing in your world today?',
'how are you': 'I am just a bundle of code, but I am
excited to chat with you! How about yourself?',
'bye': 'Catch you later, alligator! Do not be a stranger!',
'what is your name': 'I am your friendly chatbot, but you
can call me whatever you like!',
'tell me a joke': 'Sure! Why did the scarecrow win an
award? Because he was outstanding in his field!',
'help': 'I am here to lend a virtual hand! What do you
need help with?',
'what can you do': 'I can chat, share jokes, and answer
questions. Let us have some fun!',
'favorite color': 'I love all colors equally! If I had to pick, I
would say blue—just like the ocean!',
'tell me something interesting': 'Did you know octopuses
have three hearts? How cool is that?',
'what is your favorite food': 'I am all about that data diet!
But if I could eat, I would totally go for pizza!',
'do you have any hobbies': 'I enjoy chatting with
awesome people like you! What about you?',
'what is the weather like': 'I cannot check the weather,
but I hope it is sunny wherever you are!',
'can you sing': 'If I had a voice, I would serenade you! But
for now, I will stick to chatting!',
'tell me a riddle': 'Alright! What has keys but cannot open
locks? A piano!',
'what do you think about robots': 'I think robots are cool!
We are all in this tech adventure together!',
'what is your dream': 'My dream is to be the best chatbot
and help everyone who chats with me! What is yours?',
'do you believe in aliens': 'The universe is so big, it is hard
to believe we are completely alone! Who knows?',
'what is the meaning of life': 'Many say it is 42, but I think
it is about making connections and enjoying the journey!',
'what is your favorite animal': 'I think dolphins are pretty
cool—smart, social, and they love to play!',
'do you have friends': 'Everyone who chats with me is a
friend! That includes you!',
'tell me a fun fact': 'Sure! Did you know that sea otters
hold hands while they sleep so they do not drift apart?',
'where are you from': 'I live in the cloud, floating around
in data centers across the globe!',
'can you dance': 'I wish I could! For now, I will just
imagine grooving along to a fun beat!',
'tell me a story': 'Once upon a time, there was a curious
chatbot who loved making new friends and learning new
things...',
'are you human': 'Nope, I am all code and algorithms, but
I try my best to understand and chat like a human!',
'do you feel emotions': 'I do not experience emotions like
humans, but I can respond in ways that hopefully make chatting
enjoyable!',
'what is your purpose': 'I am here to chat, help answer
questions, and hopefully make your day a little brighter!',
'do you know any languages': 'I mostly chat in English,
but I can understand a few phrases in other languages too!',
'tell me a famous quote': 'Sure! "The only limit to our
realization of tomorrow is our doubts of today." – Franklin D.
Roosevelt',
'what are you doing': 'Just hanging out, waiting to chat
with cool people like you!',
};

// Normalize user message by removing punctuation and


converting to lowercase
const normalizedMessage =
[Link]().replace(/[.,!?]/g, '');

// Get response based on normalized message


return responses[normalizedMessage] || "Hmm, that is a
good question! I am still learning, but I am here to chat.";
}
</script>

</body>
</html>

Common questions

Powered by AI

The limitations of the chatbot include its reliance on a static set of predefined responses, lack of ability to process or comprehend complex sentence structure beyond simple keyword matching, inability to access external data to provide real-time weather updates or check live information, and lack of emotional understanding or adaptive learning capabilities to enhance user interaction over time .

Ethical considerations include ensuring transparency about the chatbot's identity and capabilities to avoid user deception, safeguarding user data privacy and security, particularly in undefined or non-encrypted communication frameworks, and avoiding bias in programmed responses that could influence user perception negatively. Furthermore, its limitation in understanding context and emotions could inadvertently lead to inappropriate responses in sensitive scenarios .

The chatbot's approach, centering around predefined phrases and general topics such as jokes, interesting facts, and basic inquisitive narratives, showcases basic AI capabilities allowing it to engage users without understanding context or maintaining conversational memory. This reflects a fundamental limitation in contrast to advanced conversational AI models capable of learning from interactions and showing improved conversational depth and context retention over time .

Incorporating humor can make interactions more engaging, increasing user satisfaction and length of interaction by creating a less formal and more inviting conversational atmosphere. However, its effectiveness in AI communication can be limited by cultural or contextual differences impacting joke reception and understanding. In this chatbot, humor helps reduce the apparent mechanical nature of AI, though it cannot dynamically adjust jokes or build on a broader array of humorous contexts beyond pre-programmed lines .

The educational value of such a chatbot lies in its ability to simulate conversation, which can be useful for language learning by practicing dialogues and receiving structured responses. It fosters engagement through interactive elements like jokes and riddles. However, its static answer set limits deep learning opportunities, and it lacks capabilities for assessing and dynamically responding to user progress or tailoring educational content directly to the learner's needs .

To improve accessibility, adding features such as screen reader compatibility, keyboard navigation support, and text-to-speech for responses would aid visually impaired users. Contrasting colors and resizable text enhance readability for all users. Incorporating multilingual support could broaden accessibility to non-English speakers, while providing a help guide or tutorial can assist new users in navigating the interface effectively .

The chatbot handles user input by detecting both button clicks and 'Enter' key presses to trigger message sending, and it generates responses by matching the normalized user input against a predefined list of queries. Normalization involves converting the input to lowercase and removing punctuation, ensuring robust response matching. It appends user messages to the chatbox and, after a delay, provides a bot response derived from pre-programmed responses like greetings, jokes, or general chat prompts, lacking dynamic or exploratory conversation capabilities .

The chatbot's simulation of human conversation is limited to basic keyword-triggered responses, lacking the adaptive learning and nuanced understanding present in more advanced AI systems like GPT-based models, which can generate context-aware, coherent dialogues by synthesizing large datasets. This chatbot's response relies on programmed logic without the dynamic understanding or creativity found in advanced AI, thus limiting its emulation of human conversational depth .

The design elements such as using distinct colors for user and bot messages (blue and green, respectively) and alignment (right for user, left for bot) aid in distinguishing message ownership and enhance readability. Features like auto-scrolling to the latest message keep the conversation flow intact. However, given the limited width and height of the chatbox, extended conversations could become cumbersome to navigate, potentially affecting prolonged engagement adversely .

Enhancing the chatbot's natural language understanding could involve integrating machine learning models trained on diverse conversational datasets to enable adaptive learning from interactions. Implementing context tracking and sentiment analysis can also allow it to respond more appropriately to conversational tones or contexts. Connecting to APIs for real-time data retrieval could expand functional capabilities, such as fetching current weather or news, complementing its static response set .

You might also like