JSFiddle - React, Tailwind, and code Playground

by wangtn18

HTML

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>todo list</title>
</head>

<body>
  <p id='count'> </p>
  <button onclick="addItem()">Add</button>
  <ul id="todo-list">
    <!-- <li>go a</li>
    <li>go b</li>
    <li>go mid</li> -->
  </ul>

  <script type="text/javascript">
    var todoList = [
      'go a',
      'go b',
      'go mid'
    ];
    var count = 0;
    var counter = document.getElementById('count');
    counter.innerHTML = count;
    function addItem() {
      console.log('counter');
      counter + 1;
      count = counter;
      return count;
    }
    var newtodo = document.createElement('li');
    newtodo.textContent = 'go c';
    var htmlList = document.getElementById('todo-list');
    var content = todoList.map(function (item) {
      return '<li>' + item + '</li>'
    });
    htmlList.innerHTML = content.join
      ('');
    htmlList.appendChild(newtodo);
    console.log(content)
    console.log(newtodo)
  </script>
</body>

</html>

JavaScript

var count = 0;
var counter = document.getElementById('count');
counter.innerHTML = count;
// Tạo 1 button mới nằm dưới p
// Viết code sao cho khi click button đó thì giá trị biến `count` tăng 1 đơn vị và nội dung của `counter` cũng thay đổi theo`