---
# System prepended metadata

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

---

---
tags: JS 直播班 - 2023 秋季班
---
# 🏅 Day 19 - 函式觀念四

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

### 函式的 return 觀念 

[課程影音連結](https://courses.hexschool.com/courses/2020111311/lectures/48764716)（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 / 答案                                  |
|:--------------------:|:--------------------------------------------------------------------------------:|
|詹姆士|[CodePen](https://codepen.io/z111048/pen/QWYKLJg) |
|pinyi_9|[CodePen](https://codepen.io/Wpypy/pen/xxMEKym?editors=0010) |
|Moreene|[CodePen](https://codepen.io/Moreene/pen/YzBGKRK)|
|kuanju27|[CodePen](https://codepen.io/Eero-Chiao/pen/mdvrbgV)|
|MDFK|[CodePen](https://codepen.io/maywang/pen/GRzoLPR)|
|銀光菇|[CodePen](https://codepen.io/genesynthesis/pen/LYqRYPw)|
| Uli | [CodePen](https://codepen.io/uli1313/pen/jOdMOOY?editors=0010) |
| CPing | [CodePen](https://codepen.io/CPing/pen/MWLjWeq) |
| cest_jessie | [CodePen](https://codepen.io/itsjessiechen/pen/oNmzNLg) |
| Fabio20 | [CodePen](https://codepen.io/fabio7621/pen/NWoRWdX) |
| xiaokui_71292 | [CodePen](https://codepen.io/pen?template=JjxRjyo) |
| hsiu8767 | [CodePen](https://codepen.io/hsiu8767/pen/xxMExXx?editors=0011) |
| yuling | [CodePen](https://codepen.io/igzdflpu/pen/ZEwpEKV) |
| Helen | [CodePen](https://codepen.io/milkteamonster/pen/KKJgKZG?editors=0010) |
| lychee_kk | [CodePen](https://codepen.io/kakakala/pen/GRzjRLy) |
| Ching | [CodePen](https://codepen.io/tzuchingg/pen/qBgaEWq?editors=0010) |
| Alyce | [CodePen](https://codepen.io/alycehwy/pen/qBgaEBq?editors=0010) |
| Winnie | [CodePen](https://codepen.io/codepen-io-winnie/pen/gOqwbPK?editors=0010) |
| Chia Pin | [CodePen](https://codepen.io/joker-cat/pen/OJdRPWB) |
| 精靈 | [CodePen](https://codepen.io/justafairy/pen/JjxRoMy) |
|ShangChu|[CodePen](https://codepen.io/shangchu0412/pen/PoVGwQX?editors=0010)|
| Dora | [CodePen](https://codepen.io/dorayu/pen/WNPGbPb?editors=1010) |
| ann6212 | [CodePen](https://codepen.io/yqmegupa-the-styleful/pen/oNmzgRy?editors=1112) |
| 小夏 | [CodePen](https://codepen.io/michaelhsia/pen/rNPMagm) |
| 依依 | [CodePen](https://codepen.io/Rita-Yang/pen/PoVGqqM?editors=0010) |
|風羽|[CodePen](https://codepen.io/Joy-Huang/pen/VwgKLKg?editors=0011)
| Eden |[Codepen](https://codepen.io/iseden/pen/ExrgjNE)|
| yuan2781 | [CodePen](https://codepen.io/ismebir/pen/abXmOpG)|
| damon0323 | [CodePen](https://codepen.io/swk9eny2/pen/eYxdNVV?editors=0010) |
| xin | [CodePen](https://codepen.io/Estherrrrrr999/pen/YzBGXRK) |
| claire | [CodePen](https://codepen.io/yi-wen-chen/pen/PoVGqyN) |
| yuan! | [CodePen](https://codepen.io/townyuan/pen/LYqRVoK) |
| phyllis |[CodePen](https://codepen.io/Phyllis-Cheng/pen/ZEwpbWq)|
| hsuanlee1084 | [CodePen](https://codepen.io/hsuanlee1024/pen/ZEwpbVd?editors=1010) |
| ming0712 | [CodePen](https://codepen.io/StevenHuang/pen/JjxRGjR?editors=0010) |
| Andy | [CodePen](https://codepen.io/andy31342/pen/zYeKrBq?editors=1010) |
| Vivian2857 | [CodePen](https://codepen.io/uojbohed-the-solid/pen/mdvrVWL?editors=1010) |
| Ataraxia | [CodePen](https://codepen.io/ataraxia8888/pen/ZEwWOQd) |
| kawa | [CodePen](https://codepen.io/z83xji6/pen/LYqRGre?editors=0010) |
| Yijing | [CodePen](https://codepen.io/Yi-Jing-71080635/pen/LYqRGqd?editors=0011) |
| stone4584 | [CodePen](https://codepen.io/Royen0506/pen/ZEwpQNL?editors=1111) |
| 阿賀#3700 | [CodePen](https://codepen.io/sungho/pen/MWLjyyp) |
| RX00 | [CodePen](https://codepen.io/llqzknqv-the-styleful/pen/rNPMeLG?editors=0010) |
| ⭐️小正 | [CodePen](https://codepen.io/colorgolden/pen/MWLjyvv) |
| Peng | [CodePen](https://codepen.io/H-Peng/pen/rNPMeqK?editors=0010) |
|阿榮|[Codepen](https://codepen.io/codeitaday/pen/dyapMrx)|
|celinelinnn|[CodePen](https://codepen.io/celinephoebe/pen/poGEbJL)|
| 奔跑吧(GTR150) | [CodePen](https://codepen.io/Wer-Qwe/pen/jOdyWOK) |
| jimmy.0706 | [CodePen](https://codepen.io/WeiJun-Mao/pen/rNPMLZE?editors=0010) |
| santu0868  | [CodePen](https://codepen.io/HatsumiSan/pen/BaMLLVb) |
| Ivy | [CodePen](https://codepen.io/Irene-Ke/pen/QWYKGby) |
| 荷菓かのり | [CodePen](https://codepen.io/oogxwkvw-the-builder/pen/gOqwLzp?editors=0012) |
| 維哲 | [CodePen](https://codepen.io/kwz1202/pen/poGENRR) |
| yu.t_liu | [CodePen](https://codepen.io/YuT200053/pen/ZEwpLxP) |
| nini1202desu | [CodePen](https://codepen.io/tvxq5206/pen/gOqwgzx?editors=0010) |
| shiro | [CodePen](https://codepen.io/chenghsienwang/pen/poGEPeR) |
| MY | [CodePen](https://codepen.io/ahmomoz/pen/QWYKvQd) |
| 白夜 | [CodePen](https://codepen.io/Wei903/pen/OJdRmvy?editors=1010) |
| davidtt | [CodePen](https://codepen.io/David-Tsai/pen/ZEwpKov?editors=0011) |
| noah | [CodePen](https://codepen.io/lch1222/pen/yLZaXOE?editors=0010) |
| 歐陽龍龍#1061 | [CodePen](https://codepen.io/dizzydog-rgb/pen/NWoRveQ) |
| 保羅 | [CodePen](https://codepen.io/paul-1997/pen/poGEKZw?editors=0010) |
| hsu0921 | [CodePen](https://codepen.io/HSUANIN0327/pen/zYeKaLj) |
| runweiting | [CodePen](https://codepen.io/weiting14/pen/RwvGJqb) |
| gebyman | [CodePen](https://codepen.io/gebyman/pen/QWYKZjj?editors=0010) |
| 蛋塔 |[CodePen](https://codepen.io/Hong-Game1/pen/dyapgGj)|
| tanuki5863 | [CodePen](https://codepen.io/tanuki320/pen/MWLjZyM?editors=1011) |
| 郭芙蘭#6374 | [CodePen](https://codepen.io/flora_Kuo/pen/vYbXvNJ?editors=0011) |
|   Jerry | [CodePen](https://codepen.io/ildkosxk-the-encoder/pen/eYxdbGN) |
| sponge |[CodePen](https://codepen.io/biunpujm-the-flexboxer/pen/XWOjGpo)|
| Cosmos |[CodePen](https://codepen.io/violet7755/pen/WNPoQKM)|
| Mattie | [CodePen](https://codepen.io/mattielin/pen/RwvorbV) |
| Tina02 | [CodePen](https://codepen.io/chjitlox-the-bashful/pen/qBgNWRg) |
| Joy-Chiang | [CodePen](https://codepen.io/fwysphbw-the-vuer/pen/bGzBaeK?editors=0010) |
| 小廷| [CodePen](https://codepen.io/uyxkiake-the-selector/pen/MWLbBOG?editors=0011) |
|OSN|[Codepen](https://codepen.io/osncodepen/pen/BaMQPew?editors=1112)|
|hsuhsusophie|[Codepen](https://codepen.io/hsuhsusophie/pen/abXBQXg?editors=0010)|
|Oria|[Codepen](https://codepen.io/kajing/pen/GRzNeYj?editors=0010)|
|xuan|[Codepen](https://codepen.io/xuan0915/pen/gOqgbGo?editors=0012)|
|JasonFu|[Codepen](https://codepen.io/jie-Fu/pen/bGzgVog?editors=1010)|
|Peggy|[Codepen](https://codepen.io/peggylai/pen/NWodGQX?editors=1011)|
|Rochel|[Codepen](https://codepen.io/rochelwang1205/pen/OJdWQYL?editors=1111)|
|yaoling.liang|[Codepen](https://codepen.io/Yao-Ling-L-/pen/jOdyoxE?editors=1012)
|_shun0130|[Codepen](https://codepen.io/koba60052ww/pen/PoVWgGm?editors=0010)
|Daylily|[Codepen](https://codepen.io/daylily/pen/vYbmLxN)
|shcopy|[Codepen](https://codepen.io/shcopy/pen/dyavBMj)
| shawey.1a2b | [Codepen](https://codepen.io/Shawey/pen/ExrbvMo) |
| Hank._.z | [Codepen](https://codepen.io/linoiaby-the-sans/pen/oNmoeOP?editors=1111) |
|ChrisSQR|[Codepen](https://codepen.io/ChrisSQR/pen/LYqOzQo)|
|nikkita_3544|[Codepen](https://codepen.io/vanessa7259/pen/vYbpMdd?editors=0010)|
|Iris|[Codepen](https://codepen.io/iris831206/pen/RwvQZZj)|
|macihuang|[Codepen](https://codepen.io/macy1215/pen/poGZwGN)|
|sunny_08149|[Codepen](https://codepen.io/vjgpcfpk-the-builder/pen/oNmMJPr)|
|bf_tsai|[Codepen](https://codepen.io/BF-Tsai/pen/ExreaKE?editors=1010)|
|NathanJames|[Codepen](https://codepen.io/ufo060204/pen/mdvzbdJ)|
|skypassion5000|[Codepen](https://codepen.io/skypassion5000/pen/LYqgdKz?editors=0011)|
| 辣椒 | [Codepen](https://codepen.io/chilichen118/pen/qBgQmPv) |