LoginSignup
3
0

More than 3 years have passed since last update.

初投稿!!Mathオブジェクトまとめ

Last updated at Posted at 2020-10-13

JavaScriptで数当てゲームを作る中で使用したMathオブジェクトについてまとめてみました。
(*あくまでも使用したメソッドのみです。その他のMathオブジェクトについてはまた学習次第追記します。)

そもそもMathオブジェクトとは、、、?
計算に関する多くのメソッドと数学的定数(円周率など)があらかじめ代入されたプロパティが登録されている。

⭐︎主要なメソッド・プロパティの一覧
○プロパティ編
Math.PI ---円周率を表す。約3.14159 ---

Math.js
//使い方//
console.log(Math.PI);  //予想されるリターン: 3.1415.....//

//円周を求めてみる//
function calculateCircumference(radius) {
  return Math.PI * (radius + radius);
}
calculateCircumference(1);  // 6.283185307179586

Math.SQRT1_2 ---1/2の平方根。約0.707 ---

Math.js
//使い方//
console.log(Math.SQRT1_2);  //予想されるリターン: 0.707//

//1を2の平方根で割った数を返す//
function getRoot1_2() {
  return Math.SQRT1_2;
}
getRoot1_2(); // 0.7071067811865476

Math.SQRT2 ---2の平方根。約1.414 ---

Math.js
//使い方//
console.log(Math.SQRT2);  //予想されるリターン: 1.414//

//2の平方根を返す//
function getRoot2() {
  return Math.SQRT2;
}

getRoot2(); // 1.4142135623730951
3
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
3
0