Menu



Manage

파일 목록
Study_Web > 이후/Test8.html Lines 105 | 3.0 KB
다운로드

                        <!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!-- <script>
        let multiplyAll = function (a, b) {
            let output = 1;
            for (let i = a; i <= b; i++) {
                output *= i
            }
            return output
        }

        document.write(`${multiplyAll(1, 2)} <br>`);
        // console.log(multiplyAll(1, 3));
        document.write(`${multiplyAll(1, 3)} <br>`);
    </script> -->

    <!-- 최대값을 찾는 max() 함수 만들기-->
    <!-- <script>
        const max = function (array) {
            let output = array[0];
            for (const data of array) {
                // 해당 방식으로 배열을 넣으면 자동으로 배열이 for문으로 돌아감
                if (output < data) {
                    output = data;
                }
            } return output;
        }
        document.write(max([1, 2, 3, 4]))
    </script> -->

    <!--배열 max[1,2,3,4]형태, 숫자 매개변수 max(1,2,3,4) 형태 둘 다 입력할 수 있는  max()함수 만들기-->
    <!-- <script>
        const max = function (first, ...rests) {
            let output;
            let items;
            if (Array.isArray(first)) {
                output = first[0];
                items = first;
            } else if (typeof (first) === 'number') {
                output = first;
                items = rests;
            }
            for (const data of items) {
                if (output < data) {
                    output = data;
                }
            }
            return output;
        }
        document.write(`max(배열):   ${max([1, 2, 3, 4])} <br>`);
        document.write(`max(숫자,   ...):   ${max(1, 2, 3, 4)}`);
    </script> -->

    <!--콜백함수-->
    <!-- <script>
        function callThreeTimes(callback) {
            for (let i = 0; i < 3; i++) {
                callback(i);
            }
        }
        function print(i) {
            document.write(`${i}번째 함수 호출 <br>`);
        }

        // 함수를 호출
        callTreeTimes(Print);
    </script> -->

    <!--두번째 방법-->
    <!-- <script>
        // 함수를 선언
        function callThreeTimes(callback) {
            for (let i = 0; i < 3; i++) {
                callback(i)
            }
        }

        // 함수를 호출
        callThreeTimes(function (i) {
            console.log(`${i}번째 함수 호출`)
        })
    </script> -->

    <!--forEach() 자체콜백-->
    <!-- 중간고사 나온 적 있음-->
    <script>
        const numbers = [273, 52, 103, 32, 57];

        numbers.farEach(function (value, index, array) {
            document.write(`${인덱스}번째 요소 : ${value} <br>`);
        })
    </script>
</head>

<body>

</body>

</html>