Top

01. 수학 메서드 : Math.round() / Math.floor() / Math.ceil() / Math.trunc()

번호 기본값 메서드 결과값
{
    document.querySelector(".sample01_N1").innerHTML = 1;
    document.querySelector(".sample01_Q1").innerHTML = "1.34";
    document.querySelector(".sample01_M1").innerHTML = "Math.round(1.34)";
    document.querySelector(".sample01_R1").innerHTML = Math.round(1.34);

    document.querySelector(".sample01_N2").innerHTML = 2;
    document.querySelector(".sample01_Q2").innerHTML = "1.64";
    document.querySelector(".sample01_M2").innerHTML = "Math.round(1.64)";
    document.querySelector(".sample01_R2").innerHTML = Math.round(1.64);

    document.querySelector(".sample01_N3").innerHTML = 3;
    document.querySelector(".sample01_Q3").innerHTML = "1.5";
    document.querySelector(".sample01_M3").innerHTML = "Math.round(1.5)";
    document.querySelector(".sample01_R3").innerHTML = Math.round(1.5);

    document.querySelector(".sample01_N4").innerHTML = 4;
    document.querySelector(".sample01_Q4").innerHTML = "-1.34";
    document.querySelector(".sample01_M4").innerHTML = "Math.round(-1.34)";
    document.querySelector(".sample01_R4").innerHTML = Math.round(-1.34);

    document.querySelector(".sample01_N5").innerHTML = 5;
    document.querySelector(".sample01_Q5").innerHTML = "-1.64";
    document.querySelector(".sample01_M5").innerHTML = "Math.round(-1.64)";
    document.querySelector(".sample01_R5").innerHTML = Math.round(-1.64);

    document.querySelector(".sample01_N6").innerHTML = 6;
    document.querySelector(".sample01_Q6").innerHTML = "-1.5";
    document.querySelector(".sample01_M6").innerHTML = "Math.round(-1.5)";
    document.querySelector(".sample01_R6").innerHTML = Math.round(-1.5);

    document.querySelector(".sample01_N7").innerHTML = 7;
    document.querySelector(".sample01_Q7").innerHTML = "1.34";
    document.querySelector(".sample01_M7").innerHTML = "Math.floor(1.34)";
    document.querySelector(".sample01_R7").innerHTML = Math.floor(1.34);

    document.querySelector(".sample01_N8").innerHTML = 8;
    document.querySelector(".sample01_Q8").innerHTML = "1.64";
    document.querySelector(".sample01_M8").innerHTML = "Math.floor(1.64)";
    document.querySelector(".sample01_R8").innerHTML = Math.floor(1.64);


    document.querySelector(".sample01_N9").innerHTML = 9;
    document.querySelector(".sample01_Q9").innerHTML = "-1.34";
    document.querySelector(".sample01_M9").innerHTML = "Math.floor(-1.34)";
    document.querySelector(".sample01_R9").innerHTML = Math.floor(-1.34);

    document.querySelector(".sample01_N10").innerHTML = 10;
    document.querySelector(".sample01_Q10").innerHTML = "-1.64";
    document.querySelector(".sample01_M10").innerHTML = "Math.floor(-1.64)";
    document.querySelector(".sample01_R10").innerHTML = Math.floor(-1.64);

    document.querySelector(".sample01_N11").innerHTML = 11;
    document.querySelector(".sample01_Q11").innerHTML = "1.34";
    document.querySelector(".sample01_M11").innerHTML = "Math.ceil(1.34)";
    document.querySelector(".sample01_R11").innerHTML = Math.ceil(1.34);

    document.querySelector(".sample01_N12").innerHTML = 12;
    document.querySelector(".sample01_Q12").innerHTML = "1.64";
    document.querySelector(".sample01_M12").innerHTML = "Math.ceil(1.64)";
    document.querySelector(".sample01_R12").innerHTML = Math.ceil(1.64);

    document.querySelector(".sample01_N13").innerHTML = 13;
    document.querySelector(".sample01_Q13").innerHTML = "-1.34";
    document.querySelector(".sample01_M13").innerHTML = "Math.ceil(-1.34)";
    document.querySelector(".sample01_R13").innerHTML = Math.ceil(-1.34);

    document.querySelector(".sample01_N14").innerHTML = 14;
    document.querySelector(".sample01_Q14").innerHTML = "-1.64";
    document.querySelector(".sample01_M14").innerHTML = "Math.ceil(-1.64)";
    document.querySelector(".sample01_R14").innerHTML = Math.ceil(-1.64);

    document.querySelector(".sample01_N15").innerHTML = 15;
    document.querySelector(".sample01_Q15").innerHTML = "-1.64";
    document.querySelector(".sample01_M15").innerHTML = "Math.trunc(1.64)";
    document.querySelector(".sample01_R15").innerHTML = Math.trunc(1.64);

    document.querySelector(".sample01_N16").innerHTML = 16;
    document.querySelector(".sample01_Q16").innerHTML = "-1.64";
    document.querySelector(".sample01_M16").innerHTML = "Math.trunc(-1.64)";
    document.querySelector(".sample01_R16").innerHTML = Math.trunc(-1.64);
}

02. 수학 메서드 : Math.random() : 0과 1사이의 난수 값을 반환 : 반환(숫자)

번호 기본값 메서드 결과값 클릭
{
    document.querySelector(".sample02_N1").innerHTML = 1;
    document.querySelector(".sample02_Q1").innerHTML = "0 ~ 1";
    document.querySelector(".sample02_M1").innerHTML = "Math.random()";
    document.querySelector(".sample02_R1").innerHTML = Math.random();
    document.querySelector(".sample02_R1").style.color = "#000";

    document.querySelector(".sample02_B1").addEventListener("click", ()=>{
        document.querySelector(".sample02_R1").innerHTML = Math.random();
    });

    document.querySelector(".sample02_N2").innerHTML = 2;
    document.querySelector(".sample02_Q2").innerHTML = "0 ~ 9";
    document.querySelector(".sample02_M2").innerHTML = "Math.floor(Math.random() * 10)";
    document.querySelector(".sample02_R2").innerHTML = Math.floor(Math.random() * 10);
    document.querySelector(".sample02_R2").style.color = "#000";

    document.querySelector(".sample02_B2").addEventListener("click", ()=>{
        document.querySelector(".sample02_R2").innerHTML = Math.floor(Math.random() * 10);
    });

    document.querySelector(".sample02_N3").innerHTML = 3;
    document.querySelector(".sample02_Q3").innerHTML = "10 ~ 19";
    document.querySelector(".sample02_M3").innerHTML = "Math.floor(Math.random() * 10 + 10)";
    document.querySelector(".sample02_R3").innerHTML = Math.floor(Math.random() * 10 + 10);
    document.querySelector(".sample02_R3").style.color = "#000";

    document.querySelector(".sample02_B3").addEventListener("click", ()=>{
        document.querySelector(".sample02_R3").innerHTML = Math.floor(Math.random() * 10 + 10);
    });
}

03. 수학 메서드 : Math.max() / Math.min()

번호 기본값 메서드 결과값 클릭
{
    document.querySelector(".sample03_N1").innerHTML = 1;
    document.querySelector(".sample03_Q1").innerHTML = "1, 3, 5";
    document.querySelector(".sample03_M1").innerHTML = "Math.max()";
    document.querySelector(".sample03_R1").innerHTML = Math.max(1, 3, 5);

    document.querySelector(".sample03_N2").innerHTML = 2;
    document.querySelector(".sample03_Q2").innerHTML = "-1, -3, -5";
    document.querySelector(".sample03_M2").innerHTML = "Math.max()";
    document.querySelector(".sample03_R2").innerHTML = Math.max(-1, -3, -5);

    document.querySelector(".sample03_N3").innerHTML = 3;
    document.querySelector(".sample03_Q3").innerHTML = "1, 3, 5";
    document.querySelector(".sample03_M3").innerHTML = "Math.min()";
    document.querySelector(".sample03_R3").innerHTML = Math.min(1, 3, 5);

    document.querySelector(".sample03_N4").innerHTML = 4;
    document.querySelector(".sample03_Q4").innerHTML = "-1, -3, -5";
    document.querySelector(".sample03_M4").innerHTML = "Math.min()";
    document.querySelector(".sample03_R4").innerHTML = Math.min(-1, -3, -5);
}