やりたいこと
Dの位置に A ➗ ((1 + C)にBを乗じた数) を表示させたいのですが、結果を表示すると同時にCが(1+C)の値に上書きされてしまいます。
Dに結果を表示させたまま、Cを上書きされないようにするにはどのように変えたらよいのでしょうか。
html
1<!-- 省略 --> 2 <div class="input"> 3 <label class="form-label"> A </label> 4 <input id = "asset-retirement-cost" type="cost" class="form-control" placeholder="JPY'000"> 5 <label class="form-label"> B </label> 6 <input id = "year-of-use" type="cost" class="form-control" placeholder="例)5"> 7 <label class="form-label"> C(%)</label> 8 <input id = "interest" type="cost" class="form-control" placeholder="例)1"> 9 <button type="button" id="button">計算</button> 10 <label class="form-label">結果</label> 11 <u class="present-value" id="present-value"> 12D 13 </u> 14 </div> 15<!-- 省略 -->
JavaScript
1window.addEventListener('load', function(){ 2 const cost = document.getElementById("asset-retirement-cost"); 3 const year = document.getElementById("year-of-use"); 4 const interest = document.getElementById("interest"); 5 const button = document.getElementById("button"); 6 const presentValue = document.getElementById("present-value"); 7 8 button.addEventListener('click', function() { 9 const inputCost = cost.value; 10 const inputYear = year.value; 11 const inputInterest = interest.value; 12 presentValue.innerHTML = Math.floor(inputCost/((++inputInterest.value)**inputYear)).toLocaleString(); 13 }) 14});
試したこと
先にCの値を定義してみてもだめでした。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。