0

javascriptを使用して変数を使用した計算で運動していますが、変数に上付き文字を使用する方法がわかりません。いくつかの助けを借りてJavascript calculations holding variables私は一般的に計算を行う方法を学んだが、私の新しい質問は上付き文字の使い方ですか?事前に上付き文字の計算JavaScriptの変数

<form name="Calcultor" Method="Get" id='form1'>First Number: 
 
<input type="text" name="first" size="35" id="first">+ Second Number: 
 
<input type="text" name="second" size="35" id="second"> 
 
\t 
 
<br>Answer: 
 
<input type="text" name="ans" size="35" id="ans" /> 
 
<input type="text" name="ans2" size="35" id="ans2" /> 
 
<button type="button" onclick="Calculate();">Calculate</button> 
 
</form> 
 

 
<script> 
 
function Calculate() { 
 
    var first = document.getElementById('first').value; 
 
    var second = document.getElementById('second').value; 
 
\t var ans = document.getElementById('ans').value; 
 
\t var ans2 = document.getElementById('ans2').value; 
 
\t 
 
document.getElementById('ans').value = parseInt(first) + parseInt(second); 
 
document.getElementById('ans2').value = 1.112 - 0.00043499 * parseInt(document.getElementById('ans').value)/*insert ans into a parenthensis*/ + 0.00000055 * parseInt(document.getElementById('ans').value)/*insert ans into a parenthensis and ^2 outside the parenthesis*/ - 0.00028826; 
 

 
} 
 
</script>
おかげ

+1

"_Superscript_"は指数を意味しますか? – Teemu

+1

多分[This](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/pow)はあなたが望むものですか? – Ammar

+0

はい!訂正ありがとう! –

答えて

1

javascriptのMath.pow()内の関数があります。

Math.pow(2,4)は答えに応じてあなたに^ 4 = 16 2

Math.pow(2,4); 
>16 
Math.pow(2,4.1); 
>17.148375400580687 
0

<form name="Calcultor" Method="Get" id='form1'>First Number: 
 
<input type="text" name="first" size="35" id="first">+ Second Number: 
 
<input type="text" name="second" size="35" id="second"> 
 
\t 
 
<br>Answer: 
 
<input type="text" name="ans" size="35" id="ans" /> 
 
<input type="text" name="ans2" size="35" id="ans2" /> 
 
<button type="button" onclick="Calculate();">Calculate</button> 
 
</form> 
 

 
<script> 
 
function Calculate() { 
 
    var first = document.getElementById('first').value; 
 
    var second = document.getElementById('second').value; 
 
\t var ans = document.getElementById('ans').value; 
 
\t var ans2 = document.getElementById('ans2').value; 
 
\t 
 
document.getElementById('ans').value = parseInt(first) + parseInt(second); 
 
document.getElementById('ans2').value = 1.112 - 0.00043499 * parseInt(document.getElementById('ans').value) + 0.00000055 * Math.pow(parseInt(document.getElementById('ans').value), 2) - 0.00028826; 
 

 
} 
 
</script>

更新スニペットを与えて機能するようになりました!