select によって選択された 3 つの異なる貯蓄計画のいずれかを計算するために変更する必要がある、基本的な JavaScript 金利計算機があります。
基本的なコードは正常に動作しています:
function CalculateNonComp() {
if (!parseFloat(document.noncomp.noncomp_principal.value)) {
document.noncomp.noncomp_principal.value = 0;
};
if (!parseFloat(document.noncomp.noncomp_interest.value)) {
document.noncomp.noncomp_interest.value = 1.4;
};
if (!parseFloat(document.noncomp.noncomp_length.value)) {
document.noncomp.noncomp_length.value = 30;
};
var Principal = parseFloat(document.noncomp.noncomp_principal.value);
var DailyInterest = parseFloat(document.noncomp.noncomp_interest.value) / 1;
DailyInterest = DailyInterest / 100;
var Days = parseInt(document.noncomp.noncomp_length.value) * 1;
var Result = Principal * (1 + DailyInterest * Days);
document.getElementById('noncomp_result').innerHTML = Result.toFixed(2);
}
私の問題は、if....else if....elseステートメントを実装してselectによって選択された正しい貯蓄計画を計算しようとすると始まります。
私は次のことを試しました:
function CalculateNonComp() {
if (document.noncomp.plan.value = "1");
if (!parseFloat(document.noncomp.noncomp_principal.value)) {
document.noncomp.noncomp_principal.value = 0;
};
if (!parseFloat(document.noncomp.noncomp_interest.value)) {
document.noncomp.noncomp_interest.value = 1.4;
};
if (!parseFloat(document.noncomp.noncomp_length.value)) {
document.noncomp.noncomp_length.value = 30;
};
var Principal = parseFloat(document.noncomp.noncomp_principal.value);
var DailyInterest = parseFloat(document.noncomp.noncomp_interest.value) / 1;
DailyInterest = DailyInterest / 100;
var Days = parseInt(document.noncomp.noncomp_length.value) * 1;
var Result = Principal * (1 + DailyInterest * Days);
document.getElementById('noncomp_result').innerHTML = Result.toFixed(2);
else if (document.noncomp.plan.value = "2");
if (!parseFloat(document.noncomp.noncomp_principal.value)) {
document.noncomp.noncomp_principal.value = 0;
};
if (!parseFloat(document.noncomp.noncomp_interest.value)) {
document.noncomp.noncomp_interest.value = 1.6;
};
if (!parseFloat(document.noncomp.noncomp_length.value)) {
document.noncomp.noncomp_length.value = 60;
};
var Principal = parseFloat(document.noncomp.noncomp_principal.value);
var DailyInterest = parseFloat(document.noncomp.noncomp_interest.value) / 1;
DailyInterest = DailyInterest / 100;
var Days = parseInt(document.noncomp.noncomp_length.value) * 1;
var Result = Principal * (1 + DailyInterest * Days);
document.getElementById('noncomp_result').innerHTML = Result.toFixed(2);
else(document.noncomp.plan.value = "3");
if (!parseFloat(document.noncomp.noncomp_principal.value)) {
document.noncomp.noncomp_principal.value = 0;
};
if (!parseFloat(document.noncomp.noncomp_interest.value)) {
document.noncomp.noncomp_interest.value = 1.8;
};
if (!parseFloat(document.noncomp.noncomp_length.value)) {
document.noncomp.noncomp_length.value = 90;
};
var Principal = parseFloat(document.noncomp.noncomp_principal.value);
var DailyInterest = parseFloat(document.noncomp.noncomp_interest.value) / 1;
DailyInterest = DailyInterest / 100;
var Days = parseInt(document.noncomp.noncomp_length.value) * 1;
var Result = Principal * (1 + DailyInterest * Days);
document.getElementById('noncomp_result').innerHTML = Result.toFixed(2);
}
ヒントや助けをありがとう!