round
는 반올림 메서드
ceil
은 올림 메서드
floor
내림 메서드
random
랜덤 숫자 메서드
Math.random()
으로는 내가 원하는 범위의 랜덤수를 얻을 수가 없습니다.function getRandomNumber (min, max) { return min + (Math.random() * (max - min)); } console.log(getRandomNumber(20, 50)); 결과 26.25924678942962 // 그때 그때 다름 임의의 정수로 출력하고 싶으면 (max까지 포함한) function getRandomNumber (min, max) { return min + (Math.floor(Math.random() * (max - min)) + 1); } console.log(getRandomNumber(20, 50)); 결과 27 // 그때 그때 다름 // 최소인 20부터 최대인 50까지 포함하는 범위에서 임의의 정수 반환