Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource


Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource


Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.






                // 費式數列的定義為:第 n 個數等於前兩個數的總和,因此這個數列會長的像這樣:0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233....

// 用比較數學一點的講法,就是:
// fib(0) = 0
// fib(1) = 1
// for n >=2, fib(n) = fib(n-1) + fib(n-2)

// 現在,請你寫出一個 fib 的函式,回傳位在第 n 個位置的數字

// fib(1) 預期回傳值:1
// fib(2) 預期回傳值:1
// fib(8) 預期回傳值:21

function fib (n) {
  if (n === 0) return 0
  if (n === 1) return 1
  // 遞迴最重要的是要有終止條件
  if (n >= 2) {
    let formula = fib(n-1) + fib(n-2)
    return formula

console.log( fib(8) ) // 遞迴最基礎的形式