알고리즘 풀이 모음

몫 구하기 자바스크립트

혜won 2023. 12. 19. 14:45

문제설명

정수 num1, num2가 매개변수로 주어질 때, num1을 num2로 나눈 몫을 return 하도록 solution 함수를 완성해주세요.

제한사항

0 < num1 ≤ 100
0 < num2 ≤ 100

입력

내코드

function solution(num1, num2) {
    let answer = Math.floor(num1 /num2);
    //정수의 몫만 나타내기

    
    return answer;
}

 

Math 메소드 

2023.11.26 - [JavaScript] - Math 메소드 살펴보기!Math.abs() Math.ceil() Math.floor() Math.round()Math.trunc()Math.max()Math.min()Math.pow()Math.sign() Math.sign()

 

Math 메소드 살펴보기!Math.abs() Math.ceil() Math.floor() Math.round()Math.trunc()Math.max()Math.min()Math.pow()Math.sign(

Math.abs() 절대값 반환 리턴값이 0또는 양수면 그대로 리턴값이 음수면 반대값인 양수로 반환한다. function mathAbs(a, b) { return Math.abs(a - b); } function origin(a, b) { return a - b; } console.log("Abs=>", mathAbs(2, 5));

hyewonjung-coding.tistory.com

Math.floor() 내림

console.log("Math", Math.floor(5.984 * 33)); //197
console.log("Ori", 5.984 * 33); //197.472