자바스크립트
home
2025 자바스크립트 초급 1500제
home

D0303_개념03_경우의수와개수전2

개념

<script> /* [경우의 수와 개수 전2] - 숫자 100부터 999 사이의 랜덤 숫자를 하나 저장합니다. - 해당 숫자의 각 자리수에 포함된 - 숫자 5 또는 8의 개수를 세어 출력하시오. */ /* [출력예시] 558 3 */ let r = Math.floor(Math.random() * 900) + 100; document.write(r, "<br>"); let _100 = parseInt(r / 100); let _10 = parseInt(r % 100 / 10); let _1 = r % 10; let tf = _100 == 5 || _100 == 8; let tf2 = _10 == 5 || _10 == 8; let tf3 = _1 == 5 || _1 == 8; if(tf && tf2 && tf3) { document.write(3); } if(!tf && tf2 && tf3) { document.write(2); } if(tf && !tf2 && tf3) { document.write(2); } if(tf && tf2 && !tf3) { document.write(2); } if(tf && !tf2 && !tf3) { document.write(1); } if(!tf && tf2 && !tf3) { document.write(1); } if(!tf && !tf2 && tf3) { document.write(1); } if(!tf && !tf2 && !tf3) { document.write(0); } </script>
HTML
복사

영상