数学関数のテスト
JavaScriptには数学の定数や関数が用意されています.以下にいくつかの例を示します.
詳しくは外部サイトのMath Objectを見てください.
JavaScriptの例
<SCRIPT LANGUAGE="JavaScript">
document.write("2の平方根 Math.sqrt(2.0) = ");
document.write(Math.sqrt(2.0), "<P>");
document.write("円周率π Math.PI = ");
document.write(Math.PI, "<P>"); //
document.write("Math.cos(Math.PI/3.0) = ");
document.write(Math.cos(Math.PI/3.0), "<P>");
document.write("Math.sin(Math.PI/3.0) = ");
document.write(Math.sin(Math.PI/3.0), "<P>");
document.write("Math.tan(Math.PI/4.0) = ");
document.write(Math.tan(Math.PI/4.0), "<P>");
document.write("自然対数 Math.log(10.0) = ");
document.write(Math.log(10.0), "<P>"); // 自然対数 log(10.0)
document.write("乱数 Math.random() = ");
document.write(Math.random(), "<P>");
</SCRIPT>
上記の実行結果
← 変数の使用例 → 関数の定義 ↑ 目次に戻る