■ 소스 코드
n = Math.random(); // 0~1 까지 소수점 포함 랜덤
alert(n);
n = Math.floor(Math.random() * 10) + 1; // 0~10 까지 반올림.
alert(n);
n = Math.random(); // 0~1 까지 소수점 포함 랜덤
alert(n);
n = Math.floor(Math.random() * 10) + 1; // 0~10 까지 반올림.
alert(n);
■ 포인트
Math.random()에서 Math.random(10)처럼 인수를 지정하더라도 무시됩니다. Math.random()*10처럼 할 필요가 있습니다. 틀리지 않도록 하세요.
Math.random()에서 Math.random(10)처럼 인수를 지정하더라도 무시됩니다. Math.random()*10처럼 할 필요가 있습니다. 틀리지 않도록 하세요.
댓글 없음:
댓글 쓰기