2017-05-17 2 views
0

「computeCompoundInterest」という関数を記述します。JavaScriptでこの関数で '^'を使用するにはどうすればよいですか?

プリンシパル、金利、調合頻度、および時間(年)を指定すると、 "computeCompoundInterest"は複合利益が生成された金額 を返します。

var output = computeCompoundInterest(1500, .043, 4, 6); 
console.log(output); // --> 438.8368221341061 

リファレンス: https://en.wikipedia.org/wiki/Compound_interest#Calculation_of_compound_interestこれは、生成された総複利を計算するために使用される式を示します。

問題は、私は、この式を使用しようとしていますし、私はそれぞれの計算をステップ実行しようとした右

function computeCompoundInterest(p, i, compoundingFrequency, timeInYears) { 

    p = p * (1 + (i/4)))^(compoundingFrequency*timeInYears) 

} 

それを得ることができないし、それが見えているように私はに得れば:

p = 1500 * (1 + 0.043/4)^ 4 x 6 //compoundingFrequency = 4 and timeInYears = 6 

私は何か間違っている。このwebsiteは、あなたが(1 + (i/4)))^(compoundingFrequency*timeInYears)

+2

を使用する必要がありますexponentationについては

あなたはMath.pow(x、y)を試したことがありますか? – Knerd

+1

^はbitwise XORではない。 –

+2

'^'は[bitwise XOR](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators#(Bitwise_XOR))で、 'pow'ではありません。おそらく 'p = 1500 * Math.pow((1 + 0.043/4)、4)* 6'が必要です – Matt

答えて

4

^の演算子がXOR operatorのときに10進数を取得しているようです。あなたが機能Math.powMath.pow(2,3) === 8など)または** operator(のような2**3 === 8

関連する問題