D13_ ALG101-Unit1


Posted by Christy on 2021-05-02

給一個數字 n,印出 1~n,如果碰到三個倍數,改印 Fizz;碰到五的倍數,改印 Buzz;若同時是三跟五的倍數,印 FizzBuzz

function print(n) {
    for (i = 1; i<=n; i ++) {
        if (i % 3 === 0) {
            console.log('Fizz')
        } else if (i % 5 === 0) {
            console.log('Buzz')
        } else if (i % 15 === 0) {
            console.log('FizzBuzz')
        } else console.log (i)
    }
    return n
}
console.log(print(20))

找最大值:給一個陣列,寫一個函式找出找出最大值,例如 [1, 200, 3, 50],輸出 200

function Big(arr) {
    var max = arr[0]
    for (i = 0; i < arr.length; i++) {
        if (arr[i] > max) {
            max = arr[i]
        }
    }
    return max
}

console.log(Big([10, 3, 50, 100]))









Related Posts

DEC 14 2023 PROCL-5: User does not have permission to perform a local registry operation on this key. Authentication error [User [root] [已解決]

DEC 14 2023 PROCL-5: User does not have permission to perform a local registry operation on this key. Authentication error [User [root] [已解決]

Day 139

Day 139

設計模式 7 Day 目錄

設計模式 7 Day 目錄


Comments