index.html
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My JavaScript</title>
</head>
<body>
<script src="main.js"></script>
</body>
</html>
main.js
'use strict';
{
function calcurateTotal(price, amount, rate = 1.1) {
// if (amount >= 100) {
// return price * amount;
// } else {
// return price * amount * rate;
// }
if (amount >= 100) {
// 早期リターン
return price * amount;
}
return price * amount * rate;
}
console.log(calcurateTotal(100, 100));
console.log(calcurateTotal(1000, 10));
}