TIL(2022.01.03)

조지성·2022년 1월 3일
0

TIL

목록 보기
14/78
post-thumbnail

청군VS홍군

청군과 홍군의 전쟁

  • 청군 왼쪽 100 가운데 홍군 150 오른쪽 청군 100

편지를 보내자

  • 약속 : 프로토콜

편지가 잘 전달되지 않는 경우

왼쪽 청군 입장

오른쪽 청군 입장

신뢰성 있는 통신이 필요

  1. TCP
  2. 해쉬
  3. RSA(보안)

자바스크립트 (야구게임)

무작위로 숫자뽑기

  • Math.random()사용
  • 반올림 Math.round
  • 올림 Math.ceil
  • 내림 Math.floor
<html>

<head>
    <meta charset="utf-8">
    <title>숫자야구</title>
</head>

<body>
    <form id="form">
        <input type="text" id="input">
        <button>확인</button>
    </form>
    <div id="logs"></div>
    <script>
        const $input = document.querySelector('#input');
        const $form = document.querySelector('#form');
        const $logs = document.querySelector('#logs');

        const numbers = [];
        for(let n=0 ; n < 9 ;n++){
            numbers.push(n+1); // 0~9까지 숫자 담아놓음
        }
        const answer = [];
        for(let n=0;n<4;n ++){ 
            const index = Math.floor(Math.random()*numbers.length) 
            answer.push(numbers[index]);
            numbers.splice(index,1); // 해당 인덱스를 없앰 , 땡겨짐
        }
        console.log(answer);



    </script>
</body>

</html>
profile
초보 개발자의 성장기💻

0개의 댓글