File tree Expand file tree Collapse file tree 1 file changed +10
-3
lines changed
docs/1-trial-session/09-functions Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Original file line number Diff line number Diff line change @@ -147,13 +147,13 @@ increment();
147147
148148<p ><Term type =" javascriptFunction " >関数</Term >は、複数回使用する処理を簡便に記述するためだけでなく、複雑で長い処理の一部を切り出すことにも用いることができます。</p >
149149
150- 長い処理を複数のパーツに分割すると 、次のようなメリットがあります。
150+ 長い処理をパーツに分割すると 、次のようなメリットがあります。
151151
152152- 考えるべきことが少なくなるので、読みやすい
153153- パーツごとにテストができるので、デバッグがしやすい
154154- パーツの使いまわしができる
155155
156- 次の例は、` totalTicketCount ` 枚のくじから ` hitTicketCount ` 枚を引いたときに、当たりが少なくとも 1 枚出る確率 ` winningProbability ` を、` ■■■□□□□□□□ ` のようなグラフ形式で表示するプログラムです。
156+ 次の例は、` totalTicketCount ` 枚のうち ` hitTicketCount ` 枚の当たりがあるくじから ` drawnTicketCount ` 枚を引いたときに、当たりが少なくとも 1 枚出る確率 ` winningProbability ` を、` ■■■□□□□□□□ ` のようなグラフ形式で表示するプログラムです。
157157
158158``` javascript
159159const totalTicketCount = 10 ;
@@ -179,7 +179,14 @@ for (let p = 0; p < 1; p += 0.1) {
179179このプログラムを、<Term type =" javascriptFunction " >関数</Term >を用いて確率を計算する部分とグラフとして表示する部分に分割すると、次のようになります。先頭の 2 行を読むだけでプログラム全体の処理の流れが追えるようになりました。
180180
181181``` javascript
182- const winningProbability = calculateWinningProbability (10 , 5 , 3 );
182+ const totalTicketCount = 10 ;
183+ const hitTicketCount = 5 ;
184+ const drawnTicketCount = 3 ;
185+ const winningProbability = calculateWinningProbability (
186+ totalTicketCount,
187+ hitTicketCount,
188+ drawnTicketCount,
189+ );
183190showProbabilityAsGraph (winningProbability);
184191
185192function calculateWinningProbability (
You can’t perform that action at this time.
0 commit comments