---
# System prepended metadata

title: "\U0001F3C5 Day 20 - 函式與陣列物件整合運用"
tags: [JS 直播班 - 2023 秋季班]

---

---
tags: JS 直播班 - 2023 秋季班
---
# 🏅 Day 20 - 函式與陣列物件整合運用

綜合前幾天函式觀念以及陣列物件相關操作，回答下方問題。

問題
---
依照註解敘述，完成下方程式碼（只需要補上 `...` 的部分，其餘不要更動）
```javascript=
let courses = [
  {
    title: 'Javascript',
    members: 400,
    id: 1,
    isStarted: true,
    isSoldout: true,
    tasks: ['主線任務', '每日任務']
  }
];
let newCourse = {
  title: 'Vue3',
  members: 300,
  id: 2,
  isStarted: false,
  isSoldout: true,
  tasks: ['主線任務', '每日任務']
};

// 1. 請將 courses 陣列中 id 為 1 的物件，tasks 陣列新增一筆資料為 '每日刷題'。
// 2. 請完成下方函式，將物件做為參數，判斷當課程中的 isSoldout 屬性為 true 時，
//    就將此物件新增到 courses 陣列中，並回傳 courses 陣列的長度
//   （只需要補上 ... 的部分，其餘不要更動）

function addCourse(courseObj) {
  if(...) {
    courses....;
    return ...;
    console.log('新增成功'); 
  } else {
    console.log('無法新增');
    return ...;
  }
  return;
}
let coursesLength = addCourse(newCourse);

// 3. 完成上方程式碼後，選出正確敘述
// 選項：
// (1) 最後程式碼會印出 '新增成功'，而變數 coursesLength 的值會變為 2
// (2) 最後程式碼不會印出任何字串
// (3) 如果 newCourse 的 isSoldout 屬性值為 false 時，執行 addCourse(newCourse) 將不會印出任何字串，也不會回傳 courses 陣列的長度
```


## 回報流程

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

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

<!-- 解答：  

```javascript=
let courses = [
  {
    title: 'Javascript',
    members: 400,
    id: 1,
    isStarted: true,
    isSoldout: true,
    tasks: ['主線任務', '每日任務']
  }
];
let newCourse = {
  title: 'Vue3',
  members: 300,
  id: 2,
  isStarted: false,
  isSoldout: true,
  tasks: ['主線任務', '每日任務']
};

// 1. 
courses[0].tasks.push('每日刷題');

// 2. 
function addCourse(courseObj) {
  if(courseObj.isSoldout) {
    courses.push(courseObj);
    return courses.length;
    console.log('新增成功'); 
  } else {
    console.log('無法新增');
    return courses.length;
  }
  return;
}
let coursesLength = addCourse(newCourse);

// 3. 完成上方程式碼後，選出正確敘述
// 答案：(2)
```
-->




回報區
---


|     Discord      |                                CodePen / 答案                                |
|:----------------:|:----------------------------------------------------------------------------:|
| Yijing | [CodePen](https://codepen.io/Yi-Jing-71080635/pen/PoVGNqM?editors=0011) |
| pinyi_9 | [CodePen](https://codepen.io/Wpypy/pen/WNPGKeO?editors=0011) |
| 風羽 | [CodePen](https://codepen.io/Joy-Huang/pen/XWOjBbx?editors=0011) |
| 詹姆士 | [CodePen](https://codepen.io/z111048/pen/XWOjBmx) |
| lychee_kk | [CodePen](https://codepen.io/kakakala/pen/OJdRwMb) |
| runweiting | [CodePen](https://codepen.io/weiting14/pen/poGEZzp) |
| 保羅 | [CodePen](https://codepen.io/paul-1997/pen/MWLjBKX?editors=0010) |
| Ann Chou | [CodePen](https://codepen.io/annchou_illu/pen/xxMEJbB) |
| xiaokui_71292 | [CodePen](https://codepen.io/pen?template=KKJgBMQ) |
| 銀光菇 | [CodePen](https://codepen.io/genesynthesis/pen/yLZaqeK?editors=0010) |
| kuanju27 | [CodePen](https://codepen.io/Eero-Chiao/pen/abXmjNM) |
| cest_jessie | [CodePen](https://codepen.io/itsjessiechen/pen/wvNzXVo) |
| yuling | [codepen](https://codepen.io/igzdflpu/pen/qBgayjW)|
| CPing | [codepen](https://codepen.io/CPing/pen/abXmjxz?editors=1010)|
| Ching | [codepen](https://codepen.io/tzuchingg/pen/zYeKLJg?editors=0012)|
| 精靈 | [codepen](https://codepen.io/justafairy/pen/zYeKLbO) |
| 維哲 | [codepen](https://codepen.io/kwz1202/pen/NWoRBmz) |
| Chia Pin | [codepen](https://codepen.io/joker-cat/pen/yLZaxOd) |
|Moreene|[CodePen](https://codepen.io/Moreene/pen/vYbXzgW)|
|damon0323|[CodePen](https://codepen.io/swk9eny2/pen/VwgKGLb?editors=0011)|
|Alyce|[CodePen](https://codepen.io/alycehwy/pen/NWoRLYm?editors=0010)|
|Winnie|[CodePen](https://codepen.io/codepen-io-winnie/pen/WNPGgpP?editors=0011)|
| Uli | [CodePen](https://codepen.io/uli1313/pen/WNPGabb?editors=0011) |
| claire | [CodePen](https://codepen.io/yi-wen-chen/pen/RwvGewq) |
| ann6212 | [CodePen](https://codepen.io/yqmegupa-the-styleful/pen/abXmRNE?editors=1011) |
|ShangChu|[CodePen](https://codepen.io/shangchu0412/pen/Exrgdgb?editors=0012)|
| hsu0921 | [CodePen](https://codepen.io/HSUANIN0327/pen/eYxdPzW) |
| 蛋塔| [CodePen](https://codepen.io/Hong-Game1/pen/MWLjPbp)|
| gebyman| [CodePen](https://codepen.io/gebyman/pen/ExrgdPw?editors=0011)|
| xin | [CodePen](https://codepen.io/Estherrrrrr999/pen/zYeKmwp) |
| RX00 | [CodePen](https://codepen.io/llqzknqv-the-styleful/pen/gOqwBxV?editors=0011) |
| kawa | [CodePen](https://codepen.io/z83xji6/pen/BaMLqbz?editors=0010) |
| stone4584 | [CodePen](https://codepen.io/Royen0506/pen/MWLjPzO?editors=0012) |
| SHUO | [CodePen](https://codepen.io/xrzarxkl-the-reactor/pen/rNPMQqg?editors=1010) |
| ming0712 | [CodePen](https://codepen.io/StevenHuang/pen/dyapgxB?editors=0010) |
| Allen | [CodePen](https://codepen.io/hlctw/pen/xxMEMKX) |
| dora | [CodePen](https://codepen.io/dorayu/pen/ExrgeMm?editors=1011) |
|celinelinnn|[CodePen](https://codepen.io/celinephoebe/pen/KKJgJrm)|
|Eden| [Codepen](https://codepen.io/iseden/pen/RwvGORL)|
| 荷菓かのり | [CodePen](https://codepen.io/oogxwkvw-the-builder/pen/WNPGWPV?editors=0011) |
| yu.t_liu | [CodePen](https://codepen.io/YuT200053/pen/RwvGmNq?editors=1111) |
| 奔跑吧(GTR150) | [CodePen](https://codepen.io/Wer-Qwe/pen/MWLjebq?editors=1111) |
| MY | [CodePen](https://codepen.io/ahmomoz/pen/ExrNaPj) |
| Noah | [CodePen](https://codepen.io/lch1222/pen/LYqbEjW?editors=0011) |
| Mattie | [CodePen](https://codepen.io/mattielin/pen/xxMRZbw) |
| Peng | [CodePen](https://codepen.io/H-Peng/pen/qBgqara?editors=0010) |
| 小夏 | [CodePen](https://codepen.io/michaelhsia/pen/wvNozOO) |
| Fabio20 | [CodePen](https://codepen.io/fabio7621/pen/dyaOOPm) |
| tanuki5863 | [CodePen](https://codepen.io/tanuki320/pen/XWONNVe?editors=1011) |
| Tina02 | [CodePen](https://codepen.io/chjitlox-the-bashful/pen/RwvRbJr) |
| yuan2781 | [CodePen](https://codepen.io/ismebir/pen/poGEByB) |
| santu0868 | [CodePen](https://codepen.io/HatsumiSan/pen/NWobpOJ) |
| Andy | [CodePen](https://codepen.io/andy31342/pen/zYeoYMV?editors=1012) |
| 白夜 | [CodePen](https://codepen.io/Wei903/pen/JjxbrJp?editors=0012) |
| Joy-Chiang | [CodePen](https://codepen.io/fwysphbw-the-vuer/pen/xxMRpLV?editors=0010) |
| Ataraxia | [CodePen](https://codepen.io/ataraxia8888/pen/ZEwWOQd) |
|OSN|[Codepen](https://codepen.io/osncodepen/pen/LYqbBwp?editors=1112)|
| 歐陽龍龍#1061 | [CodePen](https://codepen.io/dizzydog-rgb/pen/bGzBQqg) |
| hsuhsusophie| [CodePen](https://codepen.io/hsuhsusophie/pen/wvNoQZr?editors=0011) |
| Helen| [CodePen](https://codepen.io/milkteamonster/pen/eYxBxae?editors=1010) |
| 郭芙蘭#6374| [CodePen](https://codepen.io/flora_Kuo/pen/Jjxbzom?editors=0011) |
| Oria | [CodePen](https://codepen.io/kajing/pen/oNmYVOX?editors=0011) |
| Rogan | [CodePen](https://codepen.io/RoganHsu/pen/ZEwLzMK?editors=0011) |
| xuan | [CodePen](https://codepen.io/xuan0915/pen/xxMgbpZ?editors=0012) |
| hsuanlee1084 | [CodePen](https://codepen.io/hsuanlee1024/pen/QWYdbJN?editors=1010) |
| JasonFu | [CodePen](https://codepen.io/jie-Fu/pen/vYbgNVN?editors=1010) |
| Peggy | [CodePen](https://codepen.io/peggylai/pen/zYeNrxQ?editors=1011) |
| 依依 | [CodePen](https://codepen.io/Rita-Yang/pen/XWOpKVP?editors=0011) |
| smalljie | [CodePen](https://codepen.io/smalljie/pen/gOqgMor) |
|Rochel|[Codepen](https://codepen.io/rochelwang1205/pen/zYeNWOp)|
| yuan! | [CodePen](https://codepen.io/townyuan/pen/MWLJBbE) |
| phyllis | [CodePen](https://codepen.io/gmoxhrmc-the-styleful/pen/wvNgKMG) |
| MDFK | [CodePen](https://codepen.io/maywang/pen/rNPxbPd) |
| Vivian2857 | [CodePen](https://codepen.io/uojbohed-the-solid/pen/KKJaEry)
|yaoling.liang|[CodePen](https://codepen.io/Yao-Ling-L-/pen/qBgRzRJ?editors=0011)|
| 阿賀#3700 | [CodePen](https://codepen.io/sungho/pen/zYeZWGd) |
| Ccccc | [CodePen](https://codepen.io/CyreneTsai/pen/gOqmqGK?editors=0012) |
|Daylily | [CodePen](https://codepen.io/daylily/pen/LYqyGjP) |
|_shun0130 | [CodePen](https://codepen.io/koba60052ww/pen/rNPjbMR?editors=0011) |
|sponge| [CodePen](https://codepen.io/biunpujm-the-flexboxer/pen/WNPjZBq?editors=1011) |
|⭐️小正| [CodePen](https://codepen.io/colorgolden/pen/ExrWWLY?editors=1111) |
|davidtt| [CodePen](https://codepen.io/David-Tsai/pen/RwvVzby?editors=0011) |
|小廷| [CodePen](https://codepen.io/uyxkiake-the-selector/pen/LYqyovL?editors=0011) |
| nini1202desu | [CodePen](https://codepen.io/tvxq5206/pen/dyaROmN?editors=0011) |
|    Jerry | [CodePen](https://codepen.io/ildkosxk-the-encoder/pen/jOdLoEG?editors=0011) |
| shcopy | [CodePen](https://codepen.io/shcopy/pen/rNPzdEy) |
| Hank._.z | [CodePen](https://codepen.io/linoiaby-the-sans/pen/KKJyXpa?editors=1111) |
| ChrisSQR | [CodePen](https://codepen.io/ChrisSQR/pen/zYePEWm) |
| shawey.1a2b | [Codepen](https://codepen.io/Shawey/pen/NWowBBL) |
|nikkita_3544|[Codepen](https://codepen.io/vanessa7259/pen/PoVQoPz?editors=0010)|
|Iris|[Codepen](https://codepen.io/iris831206/pen/BaMYdwP?editors=0012)|
|hsiu8767| [CodePen](https://codepen.io/hsiu8767/pen/GRzNryj?editors=0010) |
|macihuang|[Codepen](https://codepen.io/macy1215/pen/yLZqXWM)|
|sunny_08149|[Codepen](https://codepen.io/vjgpcfpk-the-builder/pen/yLZqGdE)
|bf_tsai|[Codepen](https://codepen.io/BF-Tsai/pen/WNPgbox?editors=0010)
|NathanJames|[Codepen](https://codepen.io/ufo060204/pen/poGxzba)|
|skypassion5000|[Codepen](https://codepen.io/skypassion5000/pen/rNPqvOW?editors=0011)|
| 辣椒 | [Codepen](https://codepen.io/chilichen118/pen/xxMQdPM) |
|阿榮|[Codepen](https://codepen.io/codeitaday/pen/XWOoeKz)|


