BOBOBK

ChatGPT Automatically Generates Web Pages

TECHNOLOGY

This time, I used the viral ChatGPT to generate a web page that counts words. I asked it to create a web page to count the number of words in a text area using HTML, CSS, and JavaScript: “write full code to count the number of words in a txt area, with html,css and javascript” Here’s the response:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>Word Counter</title>
    <style>
      textarea {
        width: 100%;
        height: 200px;
        margin-bottom: 10px;
      }
      #count {
        font-size: 1.2em;
        color: #333;
        margin-bottom: 10px;
      }
    </style>
  </head>
  <body>
    <h1>Word Counter</h1>
    <textarea id="input" placeholder="Type your text here"></textarea>
    <div id="count"></div>
    <script>
      const input = document.getElementById("input");
      const count = document.getElementById("count");
      
      function updateCount() {
        const text = input.value.trim();
        const words = text.split(/s+/);
        count.textContent = `Word count: ${words.length}`;
      }
      
      input.addEventListener("input", updateCount);
    </script>
  </body>
</html>

This works fine for counting English words, but it’s not ideal for Chinese text.

Related