# 第四堂:函式設計 ## 開課提醒 1. 錄影 ## 服務加碼升級 1. 將開始提供每日助教~~爆肝~~發問服務! ![](https://i.imgur.com/yMgLIvv.png) ## function 寫法教學 - 設定指令 - 以一天會做的行為當作例子 - 參數寫法介紹 - 加法器 - return 寫法介紹 - let 宣告 - return 多個範例 ## if 與 function 的差別 - 直接寫 if 的話,.js 裡只會執行一次 - 寫 function 的話,可以依照自己需求,執行多次執行指令 ## 小組題目挑戰! * [46~50](https://chalk-freedom-ec6.notion.site/Part-1-46-50-3b71ce9efb0d4f7c9803961e27a39264) * [51~55](https://www.notion.so/Part-2-51-55-c6e273e42f314308872fc098267cade4) * [56~60](https://www.notion.so/Part-3-56-60-5ee63fa6f38140228f91312ff2d8513a) ## 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.12 ``` **BMI** ``` javascript calcBmi(178,69) //output //21.78 ``` **檢查是否需要帶雨具+if** ``` JavaScript checkWeather("雨天"); // 要帶雨具 checkWeather("晴天"); //不用帶雨具 ``` **增加陣列資料** ``` 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); ``` ## 週末任務 2. 出一題 function input、output 題目,tag 上一位學生解題 ## 第三週主線任務:樂呵呵健身房 * [任務列表](https://rpg.hexschool.com/#/training/12062543649527256883/board/content/12062543649527256884_12062543649527256902) ## 週四上課進度 * 請看到 [ForEach 章節](https://courses.hexschool.com/courses/2025-node-js/lectures/58664037)前五部即可