let 숫자 = 3.141592

ceiling : 올림

console.log("ceiling 올림", Math.ceil(숫자))

floor : 버림

console.log("floor 버림", Math.floor(숫자))

round : 반올림

console.log("round 반올림", Math.round(3.6))
console.log("round 반올림", Math.round(3.1))

abs : 절댓값

console.log("abs 절댓값", Math.abs(-3))

sqrt : 루트

console.log("sqrt 루트", Math.sqrt(64))

random : 랜덤한 숫자를 뽑아줌

 console.log("random 숫자 랜덤으로 뽑아줌", Math.random())
// 주사위뽑기 만들기
        // 1 ~ 6범위
        let 주사위번호
        // 주사위번호 = Math.random() * 6 // 0 <= x < 6의 범위가 나옴
        주사위번호 = Math.floor(Math.random() * 6 + 1) // 1 <= x < 7의 범위가 나옴
        console.log(주사위번호)

0개의 댓글