数を範囲内におさめる Math.constrain
ひとことで言うと
数値を範囲内に制限します。
ブロックとコード
0を0以上0以下の範囲に制限
ブロックの文言は公式の日本語版に合わせています(形は簡易表示です)。
Math.constrain(0,0,0)Math.constrain(0, 0, 0)引数(ひきすう)
引数とは、ブロックの中で自分で選んだり入力したりする部分のことです。
| 名前 | 選べる値 | 意味 |
|---|---|---|
| value | 数値 | 制限する値(すべてのデータ型) |
| low | 数値 | データ範囲の下限値(すべてのデータ型) |
| high | 数値 | データ範囲の上限値(すべてのデータ型) |
使用例
Keep a desired value within a realistic range of 50 to 100.
JavaScript
let desired = 155
let realistic = Math.constrain(desired, 50, 100)Python
desired = 155
realistic = Math.constrain(desired, 50, 100)