[js] 가위바위보 맞히기 (Math.random)

2022. 5. 26. 16:26js

  <script>
    document.write("<h1>컴퓨터 가위, 바위 , 보 맞히기</h1>");

    var game = prompt("가위, 바위, 보 중에 선택하세요" , "가위");
    var gameNum;

    switch (game){
      case "가위":
        gameNum = 1;
        break;

      case "바위":
        gameNum = 2;
        break;
     
      case "보":
        gameNum = 3;
        break;

      default:alert("잘못 입력했다");
      location.reload();
    }

    var com = Math.ceil(Math.random()*3)

    if(gameNum == com){
      document.write("정답");
    }else{
      document.write("땡 <br/>");
    }
  </script>

'js' 카테고리의 다른 글

[Node.js] Node.js 설치  (0) 2022.05.27
[js] 버튼 클릭 시 숫자 증가 증감  (0) 2022.05.27
[js]난수 Math.random  (0) 2022.05.26
[js] D-DAY 구하기 (Date)  (0) 2022.05.26
[js] Date 객체 - 날짜 정보  (0) 2022.05.26