<!DOCTYPE html>
<html>
  <head>
    <title>Hello World!</title>
    <link rel="stylesheet" href="styles.css" />
  </head>
  <body>
      <h1 class="title">Hello World! </h1>
      <p id="currentTime"></p>
      <script src="script.js"></script>
  </body>
</html>
<html>
<head>
    <style>
        /* CSS code for the chatbot container */
        .container {
            width: 500px;
            height: 600px;
            border: 1px solid black;
            margin: 0 auto;
            position: relative;
        }

        /* CSS code for the chatbot header */
        .header {
            width: 500px;
            height: 50px;
            background-color: #f0f0f0;
            display: flex;
            align-items: center;
            justify-content: center;
        }

        /* CSS code for the chatbot title */
        .title {
            font-size: 24px;
            font-weight: bold;
        }

        /* CSS code for the chatbot messages */
        .messages {
            width: 500px;
            height: 500px;
            overflow-y: scroll;
            padding: 10px;
        }

        /* CSS code for the user message */
        .user {
            width: 80%;
            max-width: 400px;
            min-height: 40px;
            background-color: #e0e0e0;
            border-radius: 10px;
            margin: 10px;
            padding: 10px;
            font-size: 18px;
            word-wrap: break-word;
            align-self: flex-end;
        }

        /* CSS code for the chatbot message */
        .chatbot {
            width: 80%;
            max-width: 400px;
            min-height: 40px;
            background-color: #d0d0d0;
            border-radius: 10px;
            margin: 10px;
            padding: 10px;
            font-size: 18px;
            word-wrap: break-word;
            align-self: flex-start;
        }

        /* CSS code for the chatbot input */
        .input {
            width: 500px;
            height: 50px;
            display: flex;
            align-items: center;
            justify-content: center;
        }

        /* CSS code for the chatbot text field */
        .text {
            width: 400px;
            height: 30px;
            border: 1px solid gray;
            margin: 10px;
            padding: 5px;
            font-size: 20px;
        }

        /* CSS code for the chatbot send button */
        .send {
            width: 50px;
            height: 30px;
            border: none;
            margin: 10px;
            padding: 5px;
            background-color: #c0c0c0;
            font-size: 20px;
            cursor: pointer;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="header">
            <div class="title">Chatbot</div>
        </div>
        <div class="messages" id="messages"></div>
        <div class="input">
            <input class="text" type="text" placeholder="Type something..." id="text">
            <button class="send" id="send">Send</button>
        </div>
    </div>
    <script>
        // JavaScript code for the chatbot functionality
        // Import the OpenAI module
        import { Configuration, OpenAIApi } from "openai";

        // Build the OpenAI configuration
        const configuration = new Configuration({
            organization: "org-0nmrFWw6wSm6xIJXSbx4FpTw",
            apiKey: "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",
        });

        // Create a new instance of the OpenAI API
        const openai = new OpenAIApi(configuration);

        // Get the elements by their IDs
        var messages = document.getElementById("messages");
        var text = document.getElementById("text");
        var send = document.getElementById("send");

        // Define a function to create a user message element
        function createUserMessage(content) {
            // Create a new div element
            var message = document.createElement("div");
            // Set the class name to user
            message.className = "user";
            // Set the inner text to the content
            message.innerText = content;
            // Return the message element
            return message;
        }

        // Define a function to create a chatbot message element
        function createChatbotMessage(content) {
            // Create a new div element
            var message = document.createElement("div");
            // Set the class name to chatbot
            message.className = "chatbot";
            // Set the inner text to the content
            message.innerText = content;
            // Return the message element
            return message;
        }

        // Define a function to send a user message
        function sendUserMessage() {
            // Get the value of the text field
            var content = text.value;
            // Check if the content is not empty
            if (content) {
                // Create a user message element
                var message = createUserMessage(content);
                // Append the message element to the messages div
                messages.appendChild(message);
                // Scroll to the bottom of the messages div
                messages.scrollTop = messages.scrollHeight;
                // Clear the text field
                text.value = "";
                // Send a chatbot message
                sendChatbotMessage(content);
            }
        }

        // Define a function to send a chatbot message
        function sendChatbotMessage(content) {
            // Create a chat completion request
            openai
                .createChatCompletion({
                    model: "gpt-3.5-turbo",
                    messages: [
                        {
                            role: "user",
                            content: content,
                        },
                    ],
                })
                .then((res) => {
                    // Get the chatbot response
                    var content = res.data.choices[0].message.content;
                    // Create a chatbot message element
                    var message = createChatbotMessage(content);
                    // Append the message element to the messages div
                    messages.appendChild(message);
                    // Scroll to the bottom of the messages div
                    messages.scrollTop = messages.scrollHeight;
                })
                .catch((e) => {
                    // Handle the error
                    console.log(e);
                });
        }

        // Add an event listener to the send button
        send.addEventListener("click", sendUserMessage);

        // Add an event listener to the text field
        text.addEventListener("keyup", function (event) {
            // Check if the user pressed the enter key
            if (event.keyCode === 13) {
                // Send a user message
                sendUserMessage();
            }
        });
    </script>
</body>
</html>
 

HTML Online Editor & Compiler

Write, Run & Share HTML code online using OneCompiler's HTML online Code editor for free. It's one of the robust, feature-rich online Code editor for HTML language, running on the latest version HTML5. Getting started with the OneCompiler's HTML compiler is simple and pretty fast. The editor shows sample boilerplate code when you choose language as HTML. You can also specify the stylesheet information in styles.css tab and scripts information in scripts.js tab and start coding.

About HTML

HTML(Hyper Text Markup language) is the standard markup language for Web pages, was created by Berners-Lee in the year 1991. Almost every web page over internet might be using HTML.

Syntax help

Fundamentals

  • Any HTML document must start with document declaration <!DOCTYPE html>
  • HTML documents begin with <html> and ends with </html>
  • Headings are defined with <h1> to <h6> where <h1> is the highest important heading and <h6> is the least important sub-heading.
  • Paragrahs are defined in <p>..</p> tag.
  • Links are defined in <a> tag.

    Example:

    <a href="https://onecompiler.com/html">HTML online compiler</a>
    
  • Images are defined in <img> tag, where src attribute consists of image name.
  • Buttons are defined in <button>..</button> tag
  • Lists are defined in <ul> for unordered/bullet list and <ol> for ordered/number list, and the list items are defined in <li>.

HTML Elements and Attributes

  • HTML element is everything present from start tag to end tag.
  • The text present between start and end tag is called HTML element content.
  • Anything can be a tagname but it's preferred to put the meaningful title to the content present as tag name.
  • Do not forget the end tag.
  • Elements with no content are called empty elements.
  • Elements can have attributes which provides additional information about the element.
  • In the below example, href is an attribute and a is the tag name.

    Example:

    <a href="https://onecompiler.com/html">HTML online compiler</a>
    

CSS

CSS(cascading style sheets) describes how HTML elements will look on the web page like color, font-style, font-size, background color etc.

Example:

Below is a sample style sheet which displays heading in green and in Candara font with padding space of 25px.

body{
  padding: 25px;
}
.title {
	color: #228B22;
	font-family: Candara;
}

HTML Tables

  • HTML Tables are defined in <table> tag.
  • Table row should be defined in <tr> tag
  • Table header should be defined in <th> tag
  • Table data should be defined in <td> tag
  • Table caption should be defined in <caption> tag

HTML-Javascript

  • Javascript is used in HTML pages to make them more interactive.
  • <script> is the tag used to write scripts in HTML
  • You can either reference a external script or write script code in this tag.

Example

<script src="script.js"></script>