## 下週一開始做每日任務 ## function 寫法教學 - 設定指令 - 以一天會做的行為當作例子 - 參數寫法介紹 - 加法器 - return 寫法介紹 - let 宣告 - return 多個範例 ## if 與 function 的差別 - 直接寫 if 的話,.js 裡只會執行一次 - 寫 function 的話,可以依照自己需求,執行多次執行指令 ## 小組題目挑戰! * [小組填答區](https://docs.google.com/spreadsheets/u/2/d/17Vv6u_0SIgVffcFffKmInc80H5k1fGLV2tkQbogXq5w/edit#gid=8448846) * [1~5](https://chalk-freedom-ec6.notion.site/Part-1-1-5-4eec2b31bccf4e49837beccde91a628f) * [6~10](https://chalk-freedom-ec6.notion.site/Part-2-6-10-4e0ab92608a8458f96b205fa40f0e504) * [11~15](https://chalk-freedom-ec6.notion.site/Part-3-11-15-8df3add3fb1c4186b3ed786b01cf85ff) ## input output 練習 * [示意流程圖](https://whimsical.com/RTJhrsaGwpZ8NbXvQjutB7) ### 題目列表 **字串相加** ``` javascript //input talk("早上好"); talk("晚上好"); // output // "hi,早上好" // "hi,晚上好" ``` **數字處理** ``` javascript let data = 0; //input count(2); count(3); count(5); // output //2 //5 //10 ``` **數字** ``` javascript //input count(2); count(3); count(5); // output // 4 // 9 //25 ``` **兩位數四舍五入** ``` javascript twoFixed(1.8888) twoFixed(3.1234) // output // 1.89 // 3.13 ``` **BMI** ``` javascript calcBmi(178,69) //output //21.78 ``` **檢查是否需要帶雨具+if** ``` JavaScript checkWeater("雨天"); // 要帶雨具 checkWeater("晴天"); //不用帶雨具 ``` **增加陣列資料** ``` JavaScript let data = []; add("hello"); add("你好嗎?"); // output // ["hello","你好嗎?"] ``` **增加陣列物件資料** ``` JavaScript let data = []; add("洧杰","男生"); add("葉子","女生"); // output //[ // {name:"洧杰",sex:"男生"}, // {name:"葉子",sex:"女生"} //] ``` **取物件資料** ``` JavaScript const bmiStatesData = { "overThin": { "state": "過輕", "color": "藍色" }, "normal": { "state": "正常", "color": "紅色" } } checkBmiStates("overThin"); //你的體重過輕,指數為藍色 checkBmiStates("normal"); //你的體重正常,指數為紅色 ``` ## function 裡面的 return 介紹 ``` =javascript function power(num){ console.log(num*num); } let numNum = power(5); ```