Cover photo

③2: Add Two

Add Two

2を追加

.

.

Now it's time to write a function that accepts some input.

今回は入力を受け入れる関数を書く時間です。

.

For inputs you might see the term parameter or argument. See details for a distinction between these two terms.

入力については、パラメータまたは引数という用語を見ることができます。これら2つの用語の違いについては詳細をご覧ください。

.

When calling a function with an input, we pass the input into the parenthesis:

関数に入力を渡して呼び出す場合、入力を括弧に渡します。例:

.

addOne(1);

.

When defining a function that takes an input, we will also add it to the parenthesis!Inside the function definition:

入力を受け取る関数を定義する場合は、括弧にも追加します!関数定義内部。例:

.

function addOne(input) {
    const output = input + 1; 

    return output;
}

.

The + is referred to as an addition operator. This operator takes two numbers and adds them together. For instance, 3 + 1 would evaluate to 4.

+は加算演算子として知られています。この演算子は2つの数値を取り、それらを足し合わせます。例えば、3 + 1は4に評価されます。

.

On the flip side, JavaScript also has a subtraction operator -. JavaScript has many more operators which we'll discuss in future stages!

一方、JavaScriptには減算演算子-もあります。JavaScriptには今後のステージで話すほかにもたくさんの演算子があります!

.

Your Goal: Complete the addTwo function

目標:addTwo関数を完成させる

.

1.Complete the addTwo function to take an input and add 2 to it.

入力を受け取り、それに2を足した値を返すaddTwo関数を完成させましょう。

.

2.Return that sum.

その合計値を返します。

.

.

. . Parameters and Arguments パラメータと引数 . . Both of the terms parameter and argument refer to the inputs supplied to a function. Let's take a look at a function that has two inputs: パラメータと引数という2つの用語は、関数に渡される入力を指します。2つの入力を持つ関数を見てみましょう。 . function addNumbers(a, b) { return a + b; } . In this case, there are two inputs. We can also say there are two parameters: a and b. These are the variables that are defined in the function declaration. この場合、2つの入力があります。 2つのパラメータ:aとbとも言えます。これらは関数宣言で定義される変数です。 . If we were to call this function with two values: 1 and 2: 1と2の2つの変数を使ってこの関数を呼び出す場合: . addNumbers(1, 2); . The values 1 and 2 would be considered arguments. They are the data supplied to the function, which get filled into the parameters. 値1と2は引数と考えられます。それらは関数に渡されるデータであり、パラメータに格納されます。 . This a pretty small distinction, so generally you'll hear these terms used interchangeably! The important thing is to know that when someone says parameter or argument they are referring to the function inputs. これはかなり小さな差異であり、一般的にはこれらの用語を交換して使用することができます!重要なことは、誰かがパラメータまたは引数と言った場合、それは関数入力を指しているということを知っていることです。 . . . NEXT⇒⇒ https://mirror.xyz/0x1E768F62Ab8678af5c977Ee880eC8012e1ce3c4F/wgAbXCmlH6oyHVipOETRs-OgKtb-nUYCVwERFnfXJHU