Study/JavaScript
(게임) 구구단 구현
더 멋진 세상을 꿈꾸는 개발자
2020. 5. 18. 16:52
코드를 작성하기 전에 먼저 생각해본다.
컴퓨터가 랜덤한 문제를 낸다.
|
내가 답을 입력한다.
|
2번 (no)<- 답이 맞는가? -> (yes) 1번
while (true){
let numberOne = Math.floor(Math.random() * 9) + 1;
let numberTwo = Math.floor(Math.random() * 9) + 1;
let result = numberOne * numberTwo;
let condition = true;
while (condition){
let answer = prompt(`${String(numberOne)} 곱하기 ${String(numberTwo)} 는?`)
if (result === Number(answer)){
alert('올 맞췄네😊');
condition = false;
} else {
alert('땡이지롱😜')
}
}
}
근데 위 코드는 while문이 무한반복된다는... 슬픈 단점이 있다...
출처: 제로초 강의