0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【学習記録02】JavaScript 関数で引数を使う

Posted at

関数の作り方

関数の定義方法には2種類ある。
1, アロー関数

const 定数名 = () => {
    処理内容
}

2,関数宣言

function 関数名(){
    処理内容
}

関数名の付け方

関数名は基本的に、「動詞+目的語」で作る。
例:addProduct

引数を使った処理を行う

処理内容

値段と税を引数で受け取り合計金額を計算する
3000円以下の場合、送料が500円
3000円以上の場合、送料が無料
請求金額を計算する。

コード

const calculateTotal = (price, tax) => {
    if(price * tax < 3000){
        let shoppingFee = 500;
        console.log('合計金額は' + price * tax + '円です。3000円未満なので、送料は500円です。');
        console.log('請求金額は' + (price * tax + shoppingFee) + '円です。');
    }else{
        let shoppingFee = 0;
        console.log('合計金額は' + price * tax + '円です。3000円以上なので、送料は無料になります。');
        console.log('請求金額は' + (price * tax + shoppingFee) + '円です。');
    }
}

calculateTotal(2000, 1.08);
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?