🎃 「function 帶參數」的做法:

🎃 「參數」的使用時機:當我需要做一些「較複雜的運算」,或是需要「帶資料到 function 裡面」時,就會使用到「參數」
🎃 帶入的參數可以是各種型態:number、string、boolean 都可以
 
用「一個參數」做運算
JS:
🎃 參數 = oneNum
| 12
 3
 4
 5
 6
 
 | function count(oneNum){var total = oneNum * 10;
 console.log('總數等於:' + total);
 }
 
 count(7);
 
 | 
在 Console 就會顯示「70」

用「兩個參數」做運算
JS:
🎃 參數 = oneNum和twoNum
‼️ 多個參數之間,用「逗號」來做區隔
| 12
 3
 4
 5
 6
 
 | function count(oneNum,twoNum){var total = oneNum + twoNum;
 console.log('總數等於:' + total);
 }
 
 count(20, 8);
 
 | 
在 Console 就會顯示「28」

多個函數參數
🎃 同時帶入「多個函數參數」時,也可以是「不同型態的參數」:number、string、boolean 都可以
‼️ 如果帶入的參數是「字串」,要記得用「單引號」包起來
範例
JS:
| 12
 3
 4
 5
 6
 
 | function sayHello(name, number){console.log('你好');
 document.getElementById('greet').textContent = name + '你好,我的幸運數字是' + number;
 }
 
 sayHello('juju', 17);
 
 | 
結果如下
