# 第四週小組任務-第1組
###### tags: `小組任務`、`六角學院`、`2022JS直播班`
> 小組討論
> 會議時間:2022/10/24(一) 20:00
> 會議方式:Discord 頻道
> 參與人數: 8 人
## :memo: 簽到區 (參與live 會議)
| No. | Discord Name | 簽到 10/24 :heavy_check_mark:|
| --- | ---------------- | ------------------ |
| 1 | Barret#1119 | :heavy_check_mark:|
| 2 | JustinLiu#9699 | :heavy_check_mark: |
| 3 | Data#9297 | :heavy_check_mark: |
| 4 | 教練#6451 | :heavy_check_mark: |
| 5 | jackson204#6363 |:heavy_check_mark: |
| 6 | Winnie#1306 | :heavy_check_mark: |
| 7 | XYY#2630 | |
| 8 | 健育#5748 | |
| 9 | H.L.C#2152 | :heavy_check_mark: |
| 10 | beta lin#1445 | :heavy_check_mark: |
## 小組任務
### 第一題 請挑選想討論的主題
請各組員一同討論第四關主線任務,討論方向有:
1. 觀看老師的範例影片跟程式碼,討論是否有其優化之處
2. 約時間一起練 BMI kata
3. 11/4(五) 前做完 [10 遍 BMI kata](https://rpg.hexschool.com/training/32/show?embed=https://docs.google.com/spreadsheets/d/1Vwd7XIwgzVbCL8z-Auj-em2D-GC3pIIN0xlY1dmzzNs/edit#gid=982233007),請在此勾選 v,週五統計結果
---
### 上週未完,先來研究 什麼是 this
* [this:絕對不完整,但保證好懂](https://blog.techbridge.cc/2019/02/23/javascript-this/)
* [從 ECMAScript 規範解讀 this](https://github.com/mqyqingfeng/Blog/issues/7)
* [What's THIS in JavaScript ?](https://kuro.tw/posts/2017/10/12/What-is-THIS-in-JavaScript-%E4%B8%8A/)

```javascript!
const doraemon = {
name: "多拉A夢",
age: 20,
color: "Blue",
ears: false,
toolNum: 42,
timeTravel(num) {
console.log(`回到過去${num}年!`);
},
useTool(toolName) {
console.log(`今年 ${ this.age } 歲的 ${ this.name } 拿出道具 ${ toolName }!`);
}
}
doraemon.useTool("任意門");
doraemon.timeTravel(2);
```
> 物件呼叫 永遠是物件
> function 呼叫就是 windows
```javascript!
function fun(){
console.log("this = " , this);
}
var obj = {
name:"AAA",
sayName:fun
};
var obj2 = {
name:"BB",
sayName:fun
};
console.log(obj.sayName == fun)
console.log(obj2.sayName == fun)
obj.sayName();
fun();
obj2.sayName();
fun();
/*
* 調用的方式不同,this會指向不同的對象
* fun(); => 函式調用 =>this 永遠指向 window
* obj.sayName(); =>方法調用=> this 就是那個物件
* */
```
---
### BMI KATA





* 先把字串過濾掉,直接跳錯誤
* 用 switch 寫
* [使用Switch(true)模式](https://www.twblogs.net/a/6082f197753b6adabf6e0a53)
```javascript!
let bmiHistoryData = [];
function getBmi(h, w) {
return (w / (h * 0.01) ** 2).toFixed(2);
}
//console.log(getBmi(100, 20));
function printBmi(h, w) {
let bmi = getBmi(h, w);
let result;
let msg;
switch (true) {
case (bmi < 18.5):
result = "overThin";
break;
case (bmi < 24):
result = "normal";
break;
case (bmi < 27):
result = "overWeight";
break;
case (bmi < 30):
result = "mildFat";
break;
case (bmi < 35):
result = "moderateFat";
break;
case (bmi >= 35):
result = "severeFat";
break;
default:
result = "error";
msg = "您的數值輸入錯誤,請重新輸入";
}
if (result !== "error") {
msg = `您的體重${bmiStatesData[result].state},健康指數為${bmiStatesData[result].color}`;
bmiHistoryData.push({bmi: bmi, result: result});
}
console.log(msg);
}
function showHistoryData() {
let count = bmiHistoryData.length;
let lastBmi = bmiHistoryData[count - 1].bmi;
let lastResult = bmiHistoryData[count - 1].result;
console.log(`您總共計算 ${ count } 次 BMI 紀錄,最後一次 BMI 指數為 ${ lastBmi },體重${ bmiStatesData[lastResult].state }!健康指數為${ bmiStatesData[lastResult].color }!`);
}
const bmiStatesData = {
"overThin": {
"state": "過輕",
"color": "藍色"
},
"normal": {
"state": "正常",
"color": "紅色"
},
"overWeight": {
"state": "過重",
"color": "澄色"
},
"mildFat": {
"state": "輕度肥胖",
"color": "黃色"
},
"moderateFat": {
"state": "中度肥胖",
"color": "黑色"
},
"severeFat": {
"state": "重度肥胖",
"color": "綠色"
},
}
// Test
printBmi(178, 20);
printBmi(178, 70);
printBmi(178, 85);
printBmi(178, 90);
printBmi(178, 110);
printBmi(178, 130);
printBmi("身高", "體重");
console.log(bmiHistoryData);
showHistoryData();
```
* 
* 
* function 判斷
