# 🏅 5/14 (五) 每日任務 Day 15
###### tags: `Vue 直播班 - 2021 夏季班`
題目 (請將答案貼上 CodePen)
---
參考: https://wcc723.github.io/javascript/2017/12/25/javascript-destructuring/
(1) 依據提示將以下程式碼用解構方式達成目標
```js=
// 題目一: 請使用解構,取出 name 及 age 的變數
const person = {
name: '小明',
age: 16
}
console.log(name, age); // 結果為 "小明", 16
// 題目二: 請問以下 console.log 的輸出結果為何?
let [a, b, c = 4, d = 'New', e] = [1, 2, 3];
console.log(a, b, c, d, e);
```
參考:https://wcc723.github.io/javascript/2017/12/24/javascript-spread-operator/
(2)依據提示將以下程式碼用展開方式達成目標
```js=
// 題目一: 請使用展開將 arr 的內容併入 arrNew
let arr = [1, 2, 3];
let arrNew = [?, 4, 5, 6]; // [1, 2, 3, 4, 5, 6]
console.log(arrNew);
// 題目二: 請使用展開將 restInfo 的內容併入 MingInfo
let restInfo = {
sex: '男生',
height: 178
}
let MingInfo = {
name: '小明',
age: 20,
}
```
(3) 請修改以下程式碼,透過 [參數預設值](https://developer.mozilla.org/zh-TW/docs/Web/JavaScript/Reference/Functions/Default_parameters)、[其餘參數](https://developer.mozilla.org/zh-TW/docs/Web/JavaScript/Reference/Functions/rest_parameters) 的方式完成此範例。
```js=
function getMoney(/* 填入程式碼 */) {
return money;
}
let myMoney = getMoney();
// fruits 是一個陣列
function buySomething(/* 填入程式碼 */) {
if(fruits.length > 2) {
myMoney -= 200;
}else {
myMoney -= 100;
}
console.log(`小明剩下 ${myMoney} 元`);
}
buySomething('lemon', 'watermelon', 'kiwi'); // 結果為 "小明剩下 300 元"
buySomething('lemon', 'watermelon'); // 結果為 "小明剩下 400 元"
```
回報流程
---
請同學依照下圖教學觀看解答、回報答案:

回報格式如下圖,請在「回報區」使用註解回報答案 (為了統計人數,請同學依序加上「報數」)

<!-- 解答
(1)
// 題目一
const person = {
name: '小明',
age: 16
}
const {name, age} = person;
console.log(name, age);
// 題目二
1, 2, 3, "New", undefined
(2)
// 題目一
let arr = [1, 2, 3];
let arrNew = [...arr, 4, 5, 6];
console.log(arrNew);
// 題目二
let restInfo = {
sex: '男生',
height: 178
}
let MingInfo = {
name: '小明',
age: 20,
...restInfo
}
(3)
// fruits 是一個陣列
function getMoney(money = 500) {
return money;
}
function buySomething(...fruits) {
let myMoney = getMoney();
if(fruits.length > 2) {
myMoney -= 200;
}else {
myMoney -= 100;
}
console.log(`小明剩下 ${myMoney} 元`);
}
buySomething('lemon', 'watermelon', 'kiwi');
buySomething('lemon', 'watermelon');
-->
回報區
---
<!--1:Alpha
codepen:https://codepen.io/alphatero/pen/OJpNWbw
-->
<!--2:Lina Chen
codepen:https://codepen.io/LinaChen/pen/PopNWpB
-->
<!-- 3: Vic
codepen:https://codepen.io/hsuan333/pen/NWpNdpo
-->
<!-- 4: Jay
codepen: https://codepen.io/jayredk/pen/RwpaKBJ?editors=1012
-->
<!-- 5: Harold
codepen: https://codepen.io/YuWin0805/pen/eYvZgPz
-->
<!-- 6: 小魚
codepen: https://codepen.io/jarvis1993/pen/eYvZgGp?editors=0011
-->
<!-- 7: Yiren
codepen: https://codepen.io/Yiren_Liou/pen/RwpaKJJ?editors=0012
-->
<!-- 8: youting
codepen: https://codepen.io/youtingluo/pen/zYZqZrE?editors=0011
-->
<!-- 9: Alvin Chu
codepen: https://codepen.io/wave99487chu/pen/RwpaKqB
-->
<!-- 10: 圈圈
codepen: https://codepen.io/wei-the-lessful/pen/RwpapVO
-->
<!-- 11: LiShang
codepen: https://codepen.io/li-shang/pen/vYxGgoV
<!--12: Yi Chieh
codePen: https://codepen.io/Yi-Chieh/pen/QWpNppN
-->
<!-- 13 Alysa Chan
codepen: https://codepen.io/alysachan/pen/mdWPWZJ?editors=0011
-->
<!-- 14: 陳sam
codepen:https://codepen.io/euldpliv/pen/yLMObOj?editors=1111
-->
<!-- 15: Sec
codepen: https://codepen.io/Sentiments/pen/LYWNyNw?editors=0011
-->
<!-- 16: Tori
codepen: https://codepen.io/hayen/pen/BaWNVox?editors=0011
-->
<!-- 17: Eyan
codepen: https://codepen.io/somebody1997/pen/PopNmjp?editors=1011
-->
<!-- 18: SONYKO
codepen:
https://codepen.io/s_syoujyo/pen/NWpNjBY?editors=0011
-->
<!-- 19: Ethan
codepen: https://codepen.io/blazer030/pen/gOmrWJX;
-->
<!-- 20: Chiang
codepen: https://codepen.io/ChiangJ/pen/YzZqQKV?editors=0011
-->
<!-- 21: peter.chem
codepen
https://codepen.io/JIAN-RONG/pen/qBrZmXW?editors=0012
-->
<!-- 22: Poseidon
codepen
https://codepen.io/posidomcode/pen/NWpNjmz
-->
<!-- 23: Izumi 泉
codepen: https://codepen.io/izumi-dev/pen/gOgEZzM
-->
<!-- 24: Iven
codepen: https://codepen.io/rtorihnk/pen/GRWZEPY?editors=0012
-->
<!-- 25: Joe Kuo
codepen: https://codepen.io/alertislow/pen/vYxGZZp?editors=0111
-->
<!--26: Valerie
https://codepen.io/vicky-chang/pen/KKWzqjd?editors=1012
-->
<!--26: Jordan Tseng
https://codepen.io/jordan-ttc-design/pen/qBrZmgb?editors=1010
-->
<!-- 27: wel
https://codepen.io/uwhhiaxx/pen/vYxLMJw
-->
<!-- 28: shoppingq
https://codepen.io/shoppingq/pen/rNyeGrb
-->
<!-- 29:Dah
https://codepen.io/hua0124/pen/eYvZGzL
-->
<!-- 30: Erica
https://codepen.io/ericadu/pen/qBrZPzZ
-->
<!-- 31: WuJungHan
https://codepen.io/JungHanWu/pen/JjWXrQG?editors=0012
-->
<!-- 32: YOYO
https://codepen.io/lumedkle/pen/dyvMVYb?editors=1112
-->
<!-- 33: Eric-小偉哥
https://codepen.io/pen/?editors=1111
-->
<!-- 34: Wendy Li
https://codepen.io/rockayumitw/pen/QWpNOYL?editors=0011
-->
<!-- 35: leolee
https://codepen.io/nekorice/pen/yLMOMVg
-->
<!-- 36: yijun
https://codepen.io/sandy3068/pen/xxqVpXj?editors=1111
-->
<!-- 37: tim Chou
https://codepen.io/tim-chou/pen/dyvMJZw?editors=1112
-->
<!-- 38: Larry
codePen:
https://codepen.io/manpower0708/pen/OJpNwgw?editors=1011
-->
<!-- 報數 39: RitaHuang
https://codepen.io/Rita-Rossweisse/pen/abJNWLg?editors=0011
-->
<!-- 報數 40: Stacey Huang
https://codepen.io/staceyhuang/pen/eYvZorG?editors=1111
-->
<!-- 報數 41: Alicia Lo
https://codepen.io/dkcyhyre/pen/JjWXVRp
-->
<!-- 報數 42:allen Chou
https://codepen.io/eepson123tw/pen/mdWPYEe?editors=0012
-->
<!-- 報數 42:林晉
https://codepen.io/linchinhsuan/pen/oNZxreZ?editors=0011
-->
<!-- 報數 43: 阿倫
https://codepen.io/jason5125122/pen/MWpeWyR
-->
<!-- 報數 44: Echo
https://codepen.io/pen/?editors=1112
-->
<!-- 報數 45: Tofu Tseng
https://codepen.io/Tofutseng/pen/rNyLapz?editors=0012
-->
<!-- 報數 46: Echo Hui
https://codepen.io/echohuiecho/pen/dyvXojo
-->
<!-- 報數 47: Jessie Cheng
https://codepen.io/JessieMosbi/pen/LYWZpjx?editors=0011
-->
<!-- 報數 48: Ted Kuo
https://codepen.io/TedKuo/pen/PopzNjG
-->
<!-- 報數 49: Oober
https://codepen.io/xtsjrjdv/pen/poebwyq
-->
<!-- 報數 50: twoz
https://codepen.io/twoz/pen/MWperYa?editors=0012
-->
<!-- 報數 51: jimmyFang
https://codepen.io/pohxiqqo/pen/KKWMZoM?editors=0012
-->
<!-- 報數 52: Amanda Chiang
https://codepen.io/cym199922/pen/rNyLPap?editors=0011
-->
<!-- 報數 53: Carol
https://codepen.io/taonong/pen/RwpRvEa
-->
<!-- 報數 54: Ed Huang
https://codepen.io/yide1986/pen/zYZKqYR?editors=0012
-->
<!--報數 55:Jack
https://codepen.io/pen/?editors=0011
-->
<!--報數 56:moitw
https://codepen.io/tsuifei/pen/ZEepQjL?editors=0011
-->
<!--報數 57:涂阿銘
https://codepen.io/asd40441/pen/abJmPKw?editors=0011
-->
<!--報數 58: Emily Hsi
https://codepen.io/EmilyHsi/pen/LYWbwRR
-->
<!--報數 59: 李重炫
https://codepen.io/otherway1123/pen/GRWNVbY?editors=1011
-->
<!--報數 60: Amber
https://codepen.io/amberTing/pen/XWMMPvb?editors=1011
-->