반응형
var result = Math.floor(Math.random() * 10) + 1; document.write(result); Math.floor(Math.random() * 100) + 1; //이렇게 하면, 1에서 100까지 나옴 Math.floor(Math.random() * 10); //이렇게 하면, 0에서 9까지 나옴 // Math.floor() 대신 Math.round()를 사용하여 정수화하면 안된다 // Math.round()를 사용하면 1~10까지 나오는 것이 아니라 1~11까지 나오게 됩니다.
반응형