Skip to content

Latest commit

 

History

History
66 lines (54 loc) · 1.13 KB

03.md

File metadata and controls

66 lines (54 loc) · 1.13 KB

03-01

<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>Counter</title>
</head>
<body>
  <div id="counter">0</div>
  <button id="increase">+</button>
  <button id="decrease">-</button>
  <script>
    // 에러를 발생시키는 코드: 선택자는 'counter-x'가 아니라 'counter'를 지정해야 한다.
    const $counter = document.getElementById('counter-x');
    const $increase = document.getElementById('increase');
    const $decrease = document.getElementById('decrease');

    let num = 0;
    const render = function () { $counter.innerHTML = num; };

    $increase.onclick = function () {
      num++;
      console.log('increase 버튼 클릭', num);
      render();
    };

    $decrease.onclick = function () {
      num--;
      console.log('decrease 버튼 클릭', num);
      render();
    };
  </script>
</body>
</html>

03-02

// myapp/index.js
const arr = [1, 2, 3];

arr.forEach(console.log);

03-03

// myapp/index.js
const arr = [1, 2, 3];

arr.forEach(alert);

03-04

<!DOCTYPE html>
<html>
<body>
  <script src="index.js"></script>
</body>
</html>