---
# System prepended metadata

title: "\U0001F3C5 Day 19 - 函式觀念四"
tags: [JS 直播班 - 2024 秋季班]

---

# 🏅 Day 19 - 函式觀念四

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

### 函式的 return 觀念 

可參考課程影音「函式 function - return 寫法、return 可以有多個」章節

１. 函式可以用 return 回傳一個值，並可以將該值賦予給其他變數。
```javascript=
function calcTotalScore(chineseScore, englishScore){
  let total = chineseScore + englishScore;
  return total;
}

// 將 calcTotalScore 的回傳值賦值給 markScore。
let markScore = calcTotalScore(60, 50);
console.log(markScore);
```

2. return 會中斷函式執行，可以有多個 return、搭配 if else 做使用。
```javascript=
function calcTotalScore(chineseScore, englishScore){
  let total = chineseScore + englishScore;
    
  // 在此因為 total > 100，所以在第一個 if 函式就中斷了
  if(total > 100){
    return `總分 ${total}，做的好啊 mark`;
  else{
    return `總分 ${total}，考得不是很好 mark`;
  }

  // 以下的 return 都不會執行
  return chineseScore;
  return englishScore;
}

let markScore = calcTotalScore(60, 50);
console.log(markScore);
```

問題
---
1. 下方敘述何者正確
(1) 一個函式中不能有多個 return
(2) return 的值可以賦予到變數上，像是下方程式碼中變數 `midNum` 最後的值會變為 `2` 

    ```javascript=
    let midNum = 0;
    function calcMidNum(num1,num2) {
      return (num1 + num2) / 2;
    }
    midNum = calcMidNum(1,3);
    ```
2. 觀看下方程式碼，選出正確敘述
    ```javascript=
    let awardMoney = 0
    function getAward(score) {
      if(score >= 90) {
        console.log("贏得獎金 100 元");
        return 100;
      } else if(score >= 60) {
        console.log("贏得獎金 50 元");
        return 50;
      } else {
        console.log("再接再厲！");
      }
      console.log("比賽結束！");
    }
    awardMoney = getAward(85);
    ```
    選項：
    (1) 最後會印出 2 個字串
    (2) `awardMoney` 最後的值為 85
    (3) `awardMoney` 最後的值為 50


## 回報流程

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

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

<!-- 解答：  

1. 2
2. 3
-->




回報區
---
| #   | Discord | CodePen / 答案 |
| --- | ----- | ----- |
| 01 | 泊岸 | [CodePen](https://codepen.io/qoq77416416/pen/YzmVWWe?editors=0012) | 
|02|voke|[CodePen](https://codepen.io/FiSi-the-lessful/pen/VwopYzY)|
|03|Jainee|[CodePen](https://codepen.io/Jainee0110/pen/vYoeYWm)|
| 04 | 毛巾 |[CodePen](https://codepen.io/bqdcjboa-the-solid/pen/eYqeJKz)|
| 05 | tim |[CodePen](https://codepen.io/jskrtivy-the-animator/pen/XWvzdje?editors=1010)|
|06|睿睿|[CodePen](https://codepen.io/uwmrsusb-the-solid/pen/RwXjadN?editors=0011)|
| 07 | Lobinda |[Codepen](https://codepen.io/Lobinda/pen/rNXYebK)|
| 08 | yuling  | [CodePen](https://codepen.io/yu-ling-peng/pen/mdNqEJV?editors=1011) | 
|09|mercury2508.| [CodePen](https://codepen.io/Mercury2508/pen/wvVPWKd) |
|10|Lotte| [CodePen](https://codepen.io/hmkdoxuj-the-decoder/pen/ZEgaOvV?editors=0010) |
|11|ab567ab5| [CodePen](https://codepen.io/WanTzu-Chiang/pen/PoMOzeK?editors=0011) |
|12|Ruby|[CodePen](https://codepen.io/xivgaijl-the-selector/pen/RwXjRJK)|
|13|david1819|[CodePen](https://codepen.io/David-Lin-the-vuer/pen/ZEgapMW)|
|14|陳小廷| [CodePen](https://codepen.io/ting1124/pen/RwXjozN) | 
|15|yuyuhunter_0509| [CodePen](https://codepen.io/KRcube/pen/PoMOWzb?editors=0011) |
|  16  |   KUN.    | [CodePen](https://codepen.io/barry91205/pen/PoMOpvL) | 
|17|邵|[CodePen](https://codepen.io/ukscrlno-the-typescripter/pen/MWNOpRy?editors=1111)|
|18|hao jing|[CodePen](https://codepen.io/hjxu/pen/xxvPdbp)|
|19|Kaya|[CodePen](https://codepen.io/kayaribi/pen/BaXmRRy)|
|20|jimmy.0706|[CodePen](https://codepen.io/JimmyMao/pen/rNXYmEK?editors=0012)|
|21|ycl325.etheddie|[CodePen](https://codepen.io/wdvikfuz-the-selector/pen/MWNOobB)|
|22|是在哈囉|[CodePen](https://codepen.io/miyxdhem-the-solid/pen/vYoWZLO)|
|23|JRz|[CodePen](https://codepen.io/JRZHENG/pen/poMdwOx?editors=1111)|
| 24 | GTR150 | [CodePen](https://codepen.io/Wer-Qwe/pen/vYoWJKe) |
| 25 | yuyeh_1212 | [CodePen](https://codepen.io/yuyeh1212/pen/ZEgaJLE) |
| 26 |  Chiu Hsin | [CodePen](https://codepen.io/hsin-ya/pen/JjgOyNE) |
| 27 | brucelee0629 | [CodePen](https://codepen.io/xxhdklwi-the-decoder/pen/qBeVXPm?editors=0010) |
| 28 | Mos | [CodePen](https://codepen.io/mos25399/pen/dyxZzXW?editors=0010) | 
|  29  |   Ariel    | [CodePen](https://codepen.io/ariel0510/pen/xxvPXKP?editors=0010) |
|  30  |   Rogan    | [CodePen](https://codepen.io/RoganHsu/pen/poMdWNE?editors=1111) |
|  31  |   Sonia    | [CodePen](https://codepen.io/YUJOU/pen/eYqeGoM?editors=0010) |
|  32   |    610   | [CodePen](https://codepen.io/YI-LING-LIU/pen/oNKooeg) | 
|  33   |   JIA    | [CodePen](https://codepen.io/nzaicwlw-the-styleful/pen/bGXYaaz?editors=0010) | 
|  34   |   .tsz_ying    | [CodePen](https://codepen.io/bekgnohe-the-selector/pen/MWNOpNe?editors=0011) | 
|  35   | Celine      | [CodePen](https://codepen.io/szuning/pen/XWvzYOq) | 
|  36   | joylu0902      | [CodePen](https://codepen.io/joylu0902/pen/VworXLZ) | 
|  37   | yaoling.liang | [CodePen](https://codepen.io/Yao-Ling-L-/pen/LYwOJGR?editors=1010) | 
|38|a1phaki(小k)|[CodePen](https://codepen.io/a1phaki/pen/OJKOoeq)|
| 39 | Dolce_墨 | [CodePen](https://codepen.io/DolceTseng1026/pen/rNXYqgv) | 
| 40 | Joannehu | [CodePen](https://codepen.io/nelbabkv-the-flexboxer/pen/zYgPQRp?editors=1011) | 
|  41   |  alec1203     | [CodePen](https://codepen.io/soloayaya/pen/OJKzLjK?editors=1012) | 
|  42   |  嚼勁先生     | [CodePen](https://codepen.io/James520284/pen/abeEOZL) | 
|43|ABOOS| [CodePen](https://codepen.io/guhungyin/pen/yLmpadN?editors=0012) |
|  44   |   chris    | [CodePen](https://codepen.io/chris-chen-the-selector/pen/OJKzWqj?editors=0010) | 
|  45   |   Jack    | [CodePen](https://codepen.io/kxbhixte-the-sasster/pen/GRVyyOy?editors=0010) | 
|46|Hailey|[CodePen](https://codepen.io/sxbokfja-the-flexboxer/pen/VwoyqPm?editors=0010)|
|47|Seris|[CodePen](https://codepen.io/Dale-Chien/pen/WNVdqjp)|
| 48 | Jim | [CodePen](https://codepen.io/JimChou/pen/NWQXQBO?editors=0011) | 
| 49 | Mike | [CodePen](https://codepen.io/mike2049/pen/ZEgrKxp?editors=0012) |
|  50  | jerry_66983      | [CodePen](https://codepen.io/Barry-C/pen/jOgZLPz?editors=0010) | 
| 51 | Glen_69515 |[Codepen](https://codepen.io/glenyaochih/pen/XWvZqXG) |
| 52 | ABow_Chen |[Codepen](https://codepen.io/fred39392001/pen/eYqMYXK) |
|  53   |   Emma    | [CodePen](https://codepen.io/Emma0919/pen/KKOQzKO) | 
|54|Tatsu| [CodePen](https://codepen.io/chindesu0207/pen/wvVjejB) | 
| 55 | GAVI | [CodePen](https://codepen.io/qbafldcv-the-scripter/pen/poMVdmP?editors=0011) | 
|56| Yen | [CodePen](https://codepen.io/yuxxxlouyen/pen/oNKdEvb?editors=0010) | 
|57|Hedwig| [CodePen](https://codepen.io/adirehfz-the-encoder/pen/KKOePjj) | 
|58|野鴿| [CodePen](https://codepen.io/HoshinoSyouta/pen/BaXVYrY?editors=0011) | 
|59|Ed Huang| [CodePen](https://codepen.io/yide1986/pen/RwXBrRd) | 
|60|蘑菇星星| [CodePen](https://codepen.io/brrrieon-the-vuer/pen/OJKwpWL?editors=0012) | 
|61|charlottelee| [CodePen](https://codepen.io/char849/pen/yLmqPxN) |
|62|kaka_945| [CodePen](https://codepen.io/kay945/pen/qBeMBNN) |
|63|iamcan| [CodePen](https://codepen.io/uhnxswdq-the-typescripter/pen/yLmRvbo) |
|64|維妮| [CodePen](https://codepen.io/Maggy-Lin/pen/JjgejGQ?editors=0010) |
|65|KOMATSU PEI| [CodePen](https://codepen.io/Komatsu2021/pen/ZEgmoxb?editors=0012) |
|66|Nocab| [CodePen](https://codepen.io/PeihanWang/pen/NWQoBEj?editors=0011) |
|67|Amy(咂摳)| [CodePen](https://codepen.io/nnxucgmc-the-builder/pen/gOVEVpP?editors=0011) | 
|68|Satar| [CodePen](https://codepen.io/SatarKuo/pen/ZYzKExR?editors=1111) | 
|69|Chuang|[CodePen](https://codepen.io/uidoytjq-the-solid/pen/VYZXqXy?editors=0011)


<!-- 可複製下方格式
|     |       | [CodePen]() | 
-->