@@ -0,0 +1,96 @@
+const MAX_RANDOM_NUMBER = 9;
+const MIN_RANDOM_NUMBER = 1;
+const $inputNumber = document.querySelector('.input-number');
+const $gameTable = document.querySelector(".game-table");
+
+let answer;
+
+function inputDigit(numberOfDigit){
+    $gameTable.innerHTML = "<tr><td>순서</td><td>숫자</td><td>결과</td></tr>";
+    if(numberOfDigit === "3자리"){
+        answer = randomNumber(3);
+    } else if(numberOfDigit === "4자리"){
+        answer = randomNumber(4);
+    } else if(numberOfDigit === "5자리"){
+        answer = randomNumber(5);
+    }
+}
+
+function randomNumber(numberOfDigit){
+    let result = 0;
+    let existingNumbers = [];
+    for (step = 0; step < numberOfDigit; step++) {
+        let randomNumber = Math.floor(Math.random() * (MAX_RANDOM_NUMBER - MIN_RANDOM_NUMBER) + MIN_RANDOM_NUMBER);
+        while (existingNumbers.includes(randomNumber)){
+            randomNumber = Math.floor(Math.random() * (MAX_RANDOM_NUMBER - MIN_RANDOM_NUMBER) + MIN_RANDOM_NUMBER);
+        }
+        existingNumbers.push(randomNumber);
+    }
+
+    let weight = 1;
+    for(j = 0; j < numberOfDigit; j++){
+        result += existingNumbers[j] * weight;
+        weight *= 10;
+    }
+
+    console.log(result);
+    return result;
+}
+
+let index = 1;
+function addValue(){
+    const newRow = $gameTable.insertRow();
+    const pitchResult = checkBallAndStrike(answer);
+    const convertedAnswer = answer.toString();
+
+    let isValid = 0;
+    if($inputNumber.value.length === convertedAnswer.length){
+        for(let i = 0; i < $inputNumber.value.length; i++){
+            for(let j = 0; j < $inputNumber.value.length; j++){
+                if(i !== j){
+                    if($inputNumber.value[i] === $inputNumber.value[j]){
+                        isValid = 1;
+                    }
+                }
+            }
+        }
+        if(isValid === 0){
+            const turn = newRow.insertCell(0);
+            const number = newRow.insertCell(1);
+            const result = newRow.insertCell(2);
+            turn.innerText = `${index++}`;
+            number.innerText = `${$inputNumber.value}`
+            if(pitchResult[1] === convertedAnswer.length){
+                result.innerText = `O.K.`;
+            } else{
+                result.innerText = `B: ${pitchResult[0]}, S: ${pitchResult[1]}`;
+            }
+        } else{
+            alert("올바르지 않은 값입니다.");
+        }
+       
+    } else{
+        alert("올바르지 않은 값입니다.");
+    }
+
+}
+
+function checkBallAndStrike(answer){
+    const convertedAnswer = answer.toString();
+    const convertedInputNumber = $inputNumber.value.toString();
+    let k = 0;
+    let score = [0, 0];
+    while(k < convertedAnswer.length){
+        if(convertedAnswer[k] === convertedInputNumber[k]){
+            score[1] += 1;
+        } else{
+            for(let item of convertedAnswer){
+                if(item === convertedInputNumber[k]){
+                    score[0] += 1;
+                }
+            }
+        }
+        k += 1;
+    }
+    return score;
+}
\ No newline at end of file

리뷰: 하나의 함수는 한 가지 책임만 갖도록 하는 게 좋아요!

randomNumber 함수에서는 중복되지 않는 난수를 반환하는 것이 목표인데, randomNumber 변수에 랜덤값을 넣는 행위는 그 책임과는 분리할 수 있을 것 같아요.

`let randomNumber = Math.floor(Math.random() * (MAX_RANDOM_NUMBER - MIN_RANDOM_NUMBER) + MIN_RANDOM_NUMBER);` 를 다른 함수로 분리해보는 건 어떨까요?? 😄

[참고자료](https://inpa.tistory.com/entry/OOP-%F0%9F%92%A0-%EC%95%84%EC%A3%BC-%EC%89%BD%EA%B2%8C-%EC%9D%B4%ED%95%B4%ED%95%98%EB%8A%94-SRP-%EB%8B%A8%EC%9D%BC-%EC%B1%85%EC%9E%84-%EC%9B%90%EC%B9%99)