개념
<script>
/*
[조건문과 경우의 수2]
- 숫자 1부터 10 사이의 랜덤 숫자 두 개를 저장합니다.
- 그 후, 1부터 2 사이의 랜덤 숫자를 하나 더 생성합니다.
- 생성된 숫자가 1이면 두 수의 합을,
- 2이면 두 수의 곱을 출력합니다.
*/
/*
[출력예시]
9 6
1
15
[출력예시]
2 3
2
6
*/
let r = Math.floor(Math.random() * 10) + 1;
let r2 = Math.floor(Math.random() * 10) + 1;
document.write(r, " ", r2, "<br>");
let s = Math.floor(Math.random() * 2) + 1;
document.write(s, "<br>");
let a = 0;
if(s == 1) {
a = r + r2;
}
if(s == 2) {
a = r * r2;
}
document.write(a);
</script>
HTML
복사