카테고리 없음

[JAVA SCRIPT] 홀수, 짝수 구분하기 (feat. count)

이즈 life 2021. 9. 5. 17:56

<head>

<script>
     let count = 1;

//count를 초기 1로 설정해줘야 한다.


          function hey() {
          if (count % 2 == 0) {
               alert('짝수입니다.')
          } else {
               alert('홀수입니다.');
          }
          count += 1;
          }
</script>

</head>

<body>
<div>
     <a onclick="hey()" class="btn btn-primary btn-lg" href="#" role="button">포스팅박스 열기</a>

// onclick 버튼을 생성해주고, function hey()를 넣어준다.


</div>
</body>