---
# System prepended metadata

title: "\U0001F3C5 Day 18 - 函式觀念三"
tags: [JS 直播班 - 2022 秋季班]

---

---
tags: JS 直播班 - 2022 秋季班
---
# 🏅 Day 18 - 函式觀念三

依照下方程式碼練習，並回答問題。

### 函式參數觀念 

[課程影音連結](https://courses.hexschool.com/courses/202011131/lectures/42391125)（函式參數介紹、參數寫法）

1. 函式可以帶入自定義的參數（在此為 num1, num2），並在呼叫函式的時候傳入。
```javascript=
function callNum(num1, num2){
  let total = num1 + num2;
  console.log(total);
}
// num1 等於 1, num2 等於 2
callNum(1, 2);
// num1 等於 2, num2 等於 4
callNum(2, 4);
```

2. 參數只存活在大括號。

```javascript=
function callNum(num){
  // 在此可以成功呼叫 num
  console.log(num);
}
callNum(1);
// 函數外部不可以呼叫 num，這行會報錯 
// Uncaught ReferenceError: num is not defined
console.log(num);
```


問題
---
1. 觀看以下程式碼，最後會印出什麼，以及變數 `sum` 最後的值
```javascript=
let sum = 1;
function calcNum(x) {
  sum += x;
  console.log(x);
}
calcNum(3);
```
2. 下方程式碼宣告了一個陣列（陣列內是費波那契數列），請完成下方程式碼（補上 `...` 的部分），讓 `calcNextNum()` 函式可以正常執行，並讓陣列中最後兩個數字相加後 push 到陣列中，最後 `fibonacciArr` 陣列值為 `[1, 1, 2, 3, 5, 8]`
```javascript=
let fibonacciArr = [1, 1, 2, 3, 5];
let fibonacciArrLength = fibonacciArr.length;
function calcNextNum(...) {
  ...
}
calcNextNum(fibonacciArr[fibonacciArrLength-1], fibonacciArr[fibonacciArrLength-2]);
console.log(fibonacciArr);
```



## 回報流程

將答案寫在 CodePen 並複製 CodePen 連結貼至底下回報就算完成了喔! 
解答位置請參考下圖（需打開程式碼的部分觀看）

![](https://i.imgur.com/vftL5i0.png)

<!-- 解答：  

1. 3, 
   sum: 4

2. 
```javascript=
let fibonacciArr = [1, 1, 2, 3, 5];
let fibonacciArrLength = fibonacciArr.length;
function calcNextNum(last, penultimate) {   // 參數命名可以隨意自訂
  fibonacciArr.push(last+penultimate);
}
calcNextNum(fibonacciArr[fibonacciArrLength-1], fibonacciArr[fibonacciArrLength-2]);
console.log(fibonacciArr);
```
-->




回報區
---


|       Discord        |                                  CodePen / 答案                                  |
|:--------------------:|:--------------------------------------------------------------------------------:|
|     嗶嗶羊#8042      | [Codepen](https://codepen.io/mazizlte-the-typescripter/pen/abKzPaP?editors=0011) |
|    masterYan#2480    |    [Codepen](https://codepen.io/htzwgoqt-the-looper/pen/xxzxMOG?editors=1111)    |
|      albee#9121      |              [Codepen](https://codepen.io/albee-chang/pen/abKbLeJ)               |
|   hsiung阿熊#4079    |               [Codepen](https://codepen.io/hsiungchi/pen/LYrYqPV)                |
|     君Jyun#0147      |         [codepen](https://codepen.io/Okaybeok/pen/NWzWoPY?editors=0011)          |
|      Ayre#0016       |        [Codepen](https://codepen.io/yichunlin09/pen/yLELZeG?editors=0010)        |
|    suihsilan#9485    |         [Codepen](https://codepen.io/suihsilan/pen/eYKYxNo?editors=0010)         |
|      予予#9627       |         [Codepen](https://codepen.io/kiqzcraa/pen/LYrYqNG?editors=0011)          |
|     CloThEs#7837     |                [Codepen](https://codepen.io/CloThEsZ/pen/KKeKJVG)                |
|      薯餅#3581       |             [Codepen](https://codepen.io/ColdingPoTaTo/pen/rNKNPOg)              |
|    Ron Liang#7277    |                 [Codepen](https://codepen.io/ron-go/pen/MWXWLbx)                 |
|       VT#0895        |                 [Codepen](https://codepen.io/vt197/pen/poKoGNq)                  |
|       YC#2522        |                  [CodePen](https://codepen.io/YCLu/pen/ZERzXoQ)                  |
|    jimmyFang#9575    |         [CodePen](https://codepen.io/pohxiqqo/pen/OJEJdRz?editors=0011)          |
|      Kimi #9564      |                [Codepen](https://codepen.io/kimihu91/pen/ExRxryx)                |
|     DaisyLi#4231     |    [CodePen](https://codepen.io/lidairong-gmail-com/pen/VwdwgeK?editors=0012)    |
|      Clara#1275      |         [Codepen](https://codepen.io/bsupixqu/pen/ZEREweN?editors=1112)          |
|      yumy#1940       |               [Codepen](https://codepen.io/yumy_yamg/pen/vYrYbJZ)                |
|      末次#0236       |                [Codepen](https://codepen.io/yunjulee/pen/NWzWodB)                |
|       Wei#2330       |       [Codepen](https://codepen.io/ixfjxrbo-the-typescripter/pen/gOKOqGo)        |
|     AuroraC#6539     |          [codepen](https://codepen.io/AuroraC/pen/JjZjxrX?editors=0011)          |
|      Cliff#4606      |               [Codepen](https://codepen.io/Cliff_hex/pen/MWXWLrM)                |
|    RyanTsai#8906     |                [CodePen](https://codepen.io/linlaose/pen/poKoGaB)                |
|      無名#6427       |          [CodePen](https://codepen.io/Nomoney/pen/poKoGyQ?editors=0011)          |
|   KatyChiang#1554    |          [CodePen](https://codepen.io/Kai0819/pen/gOKOqee?editors=0011)          |
|      芮綺#5224       |          [Codepen](https://codepen.io/zhan70/pen/ZEREwag?editors=1011)           |
|     Benson#6763      |                [Codepen](https://codepen.io/kumashow/pen/XWYWOYb)                |
|     Winnie#1306      |      [Codepen](https://codepen.io/WinnieWuWinnie/pen/eYKYxjm?editors=0012)       |
|      Tami#6742       |           [CodePen](https://codepen.io/wqsdqbjn-the-vuer/pen/QWxWYxY)            |
|     法希娜#3206      |   [CodePen](https://codepen.io/yiiserpf-the-encoder/pen/BaVaMPO?editors=0011)    |
|      Data#9297       |               [CodePen](https://codepen.io/kirakira72/pen/jOKOdKJ)               |
|       YI#0863        |          [CodePen](https://codepen.io/YI0305/pen/dyKyarV?editors=0012)           |
|    LHchien33#6232    |         [CodePen](https://codepen.io/lin_chien/pen/dyKyawz?editors=0010)         |
|    kenki100#0068     |                 [codepen](https://codepen.io/ken100/pen/GRGRzrM)                 |
|      威爾#1694       |                [CodePen](https://codepen.io/WILL_Wu/pen/oNyNVvG)                 |
|    mandylai#4055     |        [CodePen](https://codepen.io/mandy-lai-2/pen/OJEJdKa?editors=0012)        |
|    JustinLiu#9699    |        [CodePen](https://codepen.io/justin0227/pen/OJEJqVr?editors=0011)         |
|     Jenny真#7532     |        [CodePen](https://codepen.io/wei-chen-wu/pen/bGKGzXZ?editors=0010)        |
|      amy芳#1385      |               [CodePen](https://codepen.io/amy-chieng/pen/RwJwdRY)               |
|      yawun#0042      |               [CodePen](https://codepen.io/monicalin/pen/MWXWxey)                |
|       m_m#5493       |               [Codepen](https://codepen.io/minnn7716/pen/eYKYXBd)                |
|     魚子醬#5220      |                [CodePen](https://codepen.io/haihsuan/pen/rNKNRwy)                |
|   勁辣雞腿寶#5817    |         [Codepen](https://codepen.io/orz311013/pen/oNyNVoy?editors=1011)         |
|      小白#2406       |               [CodePen](https://codepen.io/gracewhite/pen/gOKOExE)               |
|     肉桂卷#0625      |          [CodePen](https://codepen.io/ginnlee/pen/mdKdomQ?editors=0012)          |
|      JackC#0411      |                [CodePen](https://codepen.io/key0329/pen/yLELwXO)                 |
|   出事了阿伯#9923    |        [CodePen](https://codepen.io/BradpittLai/pen/vYrYPXa?editors=1010)        |
|      圈圈#4060       |           [Codepen](https://codepen.io/wjejfcan-the-bold/pen/RwJwdmm)            |
|      kuku#3118       |        [Codepen](https://codepen.io/mengting-ku/pen/mdKdgry?editors=1011)        |
|      RJRS#9430       |                  [CodePen](https://codepen.io/RJRS/pen/XWYWQRB)                  |
|      Loran#1105      |         [CodePen](https://codepen.io/loranlin/pen/mdKdgxV?editors=1011)          |
|      azami#5986      |                 [Codepen](https://codepen.io/azami/pen/zYaYXay)                  |
|       cbs#9007       |                 [Codepen](https://codepen.io/wasdjk/pen/OJEJGEW)                 |
|     PayRoom#8328     |               [CodePen](https://codepen.io/water38198/pen/XWYWQoO)               |
|   jacky010080#0880   |       [CodePen](https://codepen.io/Yen-Jung-Chen/pen/wvXvbwP?editors=0111)       |
|       Rr#2215        |              [Codepen](https://codepen.io/albee-chang/pen/abKbLeJ)               |
|     Judy☻ #7874      |         [CodePen](https://codepen.io/hsiaohan/pen/oNyNRNj?editors=0011)          |
|     Arista#5802      |              [CodePen](https://codepen.io/arista-hsieh/pen/xxzxNRG)              |
|   Cookie SSS#6991    |   [CodePen](https://codepen.io/sqhjikpa-the-selector/pen/xxzxNjO?editors=1011)   |
|      k.sin#3115      |          [Codepen](https://codepen.io/sin588/pen/ExRxzzg?editors=0011)           |
|      Rena#6249       |        [Codepen](https://codepen.io/aureate0116/pen/Yzvzopv?editors=0011)        |
|      Chung#5951      |          [Codepen](https://codepen.io/yuju16/pen/jOKOjQr?editors=0010)           |
|    Potatolee#7749    |               [Codepen](https://codepen.io/potatoleee/pen/YzvzorO)               |
|     Yishan#4902      |   [Codepen](https://codepen.io/gdjrehhw-the-animator/pen/jOKOgNy?editors=0010)   |
|      Hilda#7085      |           [Codepen](https://codepen.io/vwquikad-the-vuer/pen/mdKdNxV)            |
|   William Lai#0196   |               [Codepen](https://codepen.io/lai-weihan/pen/OJEJKvb)               |
|      Yiru#0236       |          [Codepen](https://codepen.io/yiru94/pen/QWxWeRm?editors=0011)           |
|    hannahTW#2224     |         [Codepen](https://codepen.io/hangineer/pen/PoaoMEz?editors=0011)         |
|    shinyhung#3825    |         [Codepen](https://codepen.io/sean_1215/pen/dyKPbMX?editors=1111)         |
|     心幻羽#0056      |        [Codepen](https://codepen.io/linglingsyu/pen/PoawYJQ?editors=1111)        |
|    我是泇吟#5189     |                [CodePen](https://codepen.io/kljuqbxs/pen/GRGgRRB)                |
|    Judy Wei#6103     |                [CodePen](https://codepen.io/Judy0718/pen/ExRaxNm)                |
| charlottelee849#0366 |       [CodePen](https://codepen.io/charlotte-lee/pen/ExRaxZm?editors=1111)       |
|     Amberhh#2465     |                [Codepen](https://codepen.io/Amberhh/pen/XWYWOKv)                 |
|      雷雷#7844       |        [Codepen](https://codepen.io/lei-yi-jie/pen/poKvvgw?editors=0010)         |
|   Sentiments#4883    |        [codepen](https://codepen.io/Sentiments/pen/GRGggxZ?editors=0011)         |
|     SASIMI#5099      |              [Codepen](https://codepen.io/sashimi1327/pen/qBYMXLa)               |
|      萱仔#0781       |        [Codepen](https://codepen.io/ting-hsuan/pen/yLEyymx?editors=0010)         |
|     RayChen#6088     |              [Codepen](https://codepen.io/raychen1996/pen/gOKbpYm)               |
|      yoyo#1003       |       [Codepen](https://codepen.io/crpbugqy-the-typescripter/pen/VwdYYJe)        |
|     WEI_RIO#9342     |          [Codepen](https://codepen.io/wei_wu/pen/mdKyJyR?editors=0011)           |
|   jackson204#6363    |               [Codepen](https://codepen.io/jackson204/pen/bGKNdWM)               |
|       威0#6919       |        [Codepen](https://codepen.io/n0918679182/pen/RwJNPjZ?editors=0012)        |
|     黑松胖#4836      |      [Codepen](https://codepen.io/yi-chien-hsieh/pen/gOKbpev?editors=0012)       |
|       mou#2215       |       [Codepen](https://codepen.io/shihchiehlan/pen/GRGgpZX?editors=0010)        |
|      竹輪#3335       |              [Codepen](https://codepen.io/chikuwa0120/pen/KKewdMK)               |
|    Silvialu#4521     |              [Codepen](https://codepen.io/Silvia091640/pen/abKzdwQ)              |
|     CofCat#9226      |         [Codepen](https://codepen.io/cofcat456/pen/VwdYawe?editors=1011)         |
|      大衛#4869       |         [Codepen](https://codepen.io/exnsrpjc/pen/NWzPNOE?editors=0011)          |
|      狸貓#5863       |         [Codepen](https://codepen.io/tanuki320/pen/ExRaxxN?editors=0010)         |
|      蓁心#6229       | [Codepen](https://codepen.io/tlorfrnl-the-typescripter/pen/jOKErrN?editors=0011) |
|    Hironaka#7367     |              [Codepen](https://codepen.io/Hironaka0815/pen/xxzbEGJ)              |
|    Jamie Wu#9345     |                [Codepen](https://codepen.io/Wu220103/pen/bGKNwrB)                |
|    Ruby Chen#7452    |         [Codepen](https://codepen.io/ruby92429/pen/zYaxKoa?editors=0011)         |
|     Mylène#2481      |              [Codepen](https://codepen.io/hamajibashi/pen/NWzPRvd)               |
|     hungya#0773      |         [Codepen](https://codepen.io/hungya777/pen/yLEyazp?editors=0011)         |
|     黃士桓#7654      |             [codePen](https://codepen.io/shr-huan-huang/pen/MWXYJWY)             |
|     楓之聲#6945      |               [Codepen](https://codepen.io/sshane258/pen/WNyboBm)                |
|       yen#5757       |       [Codepen](https://codepen.io/TZU-HUANG-YEN/pen/oNdPgqY?editors=0011)       |
|     yoshidc#0455     |                [Codepen](https://codepen.io/yoshiyyc/pen/qBKEpQG)                |
|      母湯#7211       |        [Codepen](https://codepen.io/tommyshih77/pen/poKvpBL?editors=0011)        |
|     黑白兔#0684      |               [Codepen](https://codepen.io/johnny329/pen/ZERYrWV)                |
|     哈囉哈#5196      |        [CodePen](https://codepen.io/bill0841205/pen/ExRaENZ?editors=1011)        |
|    beta lin#1445     |                [CodePen](https://codepen.io/linbeta/pen/XWYJEzp)                 |
|   Yuna Huang#2692    |         [CodePen](https://codepen.io/Yuna1002/pen/vYrERVQ?editors=0010)          |
|     艾芮絲#6060      |               [CodePen](https://codepen.io/wangyingju/pen/wvXBjoM)               |
|      Paul#7426       |         [CodePen](https://codepen.io/paul-1997/pen/mdKyLqy?editors=0011)         |
|      homer#1525      |                [CodePen](https://codepen.io/Buckhorn/pen/LYrEdBd)                |
|      Lucie#3831      |                [Codepen](https://codepen.io/bisespei/pen/YzvPYeK)                |
|      柔柔#1716       |          [Codepen](https://codepen.io/rouchen/pen/ZERYjqB?editors=1011)          |
|    banazita#5143     |         [CodePen](https://codepen.io/banazita/pen/gOKOVxP?editors=1111)          |
|      Ohno#1144       |         [Codepen](https://codepen.io/mmaa7850/pen/RwJNeoo?editors=0011)          |
|    jin.huang#4666    |         [Codepen](https://codepen.io/haha1196/pen/gOKbEEy?editors=1010)          |
|     Mia小福#4473     |                [Codepen](https://codepen.io/a0950271/pen/NWzPVmO)                |
|     J_u_d_y#5993     |          [Codepen](https://codepen.io/J_u_d_y/pen/LYrEKvm?editors=1111)          |
|      Dora#8223       |         [Codepen](https://codepen.io/mwebwvuq-the-flexboxer/pen/YzvXzra)         |
|      健育#5748       |         [Codepen](https://codepen.io/c1317156/pen/NWzqbWg?editors=0012)          |
|      Greta#0837      |                [CodePen](https://codepen.io/gretali/pen/bGKdBwo)                 |
|   Ryan Chiang#6649   |                 [Codepen](https://codepen.io/pen/?editors=0012)                  |
|      教練#6451       |             [Codepen](https://codepen.io/monkeybear721/pen/gOKOEwZ)              |
|     IreneY#0086      |           [codepen](https://codepen.io/HalfPlannedJourney/pen/GRGJrGY)           |
|      阿風#6890       |         [codepen](https://codepen.io/Afonguwu/pen/xxzGdZN?editors=0110)          |
|     FiReBrO#0557     |         [codepen](https://codepen.io/firebro42/pen/WNyvOrL?editors=0011)         |
|       yaru#6308               |       [codepen](https://codepen.io/lszaietc/pen/LYrEKWj)                                                                           |
| 安o#2448 | [codePen](https://codepen.io/JzhenAn/pen/LYrVqaG?editors=1111) |
|kevin #6131 | [codePen](https://codepen.io/xlqjezvc-the-encoder/pen/MWXwxYd?editors=1011) |
|sophiee#7015|[Codepen](https://codepen.io/sophiee2727/pen/dyKoaxO?editors=1011)|
|王懷英#7271|[Codepen](https://codepen.io/huaiying/pen/PoaqLrV)|
|Eileen#6454|[Codepen](https://codepen.io/Eileen-io/pen/xxzGeMy)|
| 富#0389 | [codePen](https://codepen.io/spring40747/pen/yLENWJK?editors=1111) |
| Awei#0720 | [codePen](https://codepen.io/Aweishi/pen/LYrpZyx?editors=0010) |
|YU#0618|[Codepen](https://codepen.io/yoken_/pen/oNyjLVo)|
| Powei#8484|[codepen](https://codepen.io/harrison-wei-lai/pen/QWxjKQN?editors=1111)|
|ling chang#1024|[Codepen](https://codepen.io/ling-chang/pen/xxzwRde)|
|cotton#7163|[Codepen](https://codepen.io/cottonT/pen/OJEymKO?editors=0010)|
|Chloe#5422|[Codepen](https://codepen.io/Ironchloe/pen/VwdvzpG?editors=0010)|
|Ringo#7583|[Codepen](https://codepen.io/ringolai1988/pen/jOKbLQV?editors=1010)|
|Jhen#4563|[Codepen](https://codepen.io/su-jhen/pen/WNyQEVo)|
|Shuo#1596|[Codepen](https://codepen.io/chiangchungshuo/pen/jOKbaNv)|
|艸良#2846|[Codepen](https://codepen.io/momoninainai/pen/YzvyLad?editors=1111)|
|Peng#9811|[Codepen](https://codepen.io/peng-027/pen/mdKeLGY)|
|shio#1414|[Codepen](https://codepen.io/shioyen/pen/dyKYaBG?editors=1111)|
|bingsu#2362|[Codepen](https://codepen.io/pmyfr/pen/wvXKbQe?editors=0010)|
|How#5806|[Codepen](https://codepen.io/howtobefine/pen/PoaZdrM)|
|mei#8421|[Codepen](https://codepen.io/Shila-Chen/pen/WNyrBGx?editors=0010)|
|yuling#1634|[codepen](https://codepen.io/igzdflpu/pen/abKNpqo)|
|kancheng#3915|[CodePen](https://codepen.io/kancheng/pen/xxzVqXq?editors=0111)|
|阿蘇#8531|[CodePen](https://codepen.io/susu3131/pen/ExRKRJd?editors=0011)|
|軟綿綿 (๑•ᴗ•๑) ♡#3627|[CodePen](https://codepen.io/Connie-Chien/pen/WNywKRX?editors=0011)|
|三隻小貓#1905|[CodePen](https://codepen.io/bagelover/pen/GRGZXoy)|
|Azi Hsieh#2861|[CodePen](https://codepen.io/AziHsieh/pen/WNywaRr)|
|Nini Chen#5790|[CodePen](https://codepen.io/ninistyle/pen/oNyLzEw?editors=0012)|
|Cynthia1111#1822|[CodePen](https://codepen.io/Cynthia1111/pen/gOKMxzK)|
|Tuhacrt#0008|[codepen](https://codepen.io/Tuhacrt/pen/ExRyzjZ)|
|Cream#3449|[codepen](https://codepen.io/frxdwbbi-the-sasster/pen/MWXjJGV?editors=0011)|
|L0F0#8733|[codepen](https://codepen.io/l0f0/pen/RwJojRd?editors=0011)|
|Lou#0085|[codepen](https://codepen.io/Lusie_H/pen/MWXbLOY?editors=0011)|
|meimei#9524|[codepen](https://codepen.io/isnrudav/pen/jOKLjNZ?editors=1111)|
|yuchenye#6119|[codepen](https://codepen.io/yuchen/pen/yLEzYoQ)|
|H.L.C#2152|[CodePen](https://codepen.io/hsin-liang/pen/bGKogjM)|
|Baozi#2042|[CodePen](https://codepen.io/lillianyu/pen/wvXpvVP)|
|pss940909#8650|[CodePen](https://codepen.io/pss940909/pen/oNyEXbw?editors=1011)|
|samger#0808|[CodePen](https://codepen.io/lee-wei-hong/pen/jOKXdzP?editors=1111)|


