내가 콘솔에서 btn.onClick을 호출이 오류 받고 있어요의 설정할 수 없습니다 재산 '온 클릭'catch되지 않은 유형의 오류 : 널 (null)
코드를 {catch되지 않는 형식 오류가 null의 '온 클릭'속성을 설정할 수 없습니다} 여기 :
===============의 HTML ==================
<!DOCTYPE html>
<html>
<head>
<title>Calculator</title>
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>
<div class="container">
<h3 class="billboard">Wacky Expressions Assignment</h3>
<p><b>Cost of Shoe Strings</b>:<input type="text" id="inCost"/></p>
<p><b>Down Payment</b>:<input type="text" id="inDown"/></p>
<p><b>APR (Intrest)</b>:<input type="text" id="inAPR"/></p>
<p><b>Term (How long)</b>:<input type="text" id="inTime"/></p>
<p><button id="btnCalculate">Calculate Payments</button></p>
<p><b>Monthly Payments</b>:<span id="outMonthly"/></p>
</div>
<script language="JavaScript" src="js/script.js" type="text/javascript"></script>
</body>
</html>
=== ============ JS ================
//The Formula: c = (r * p)/(1 - (Math.pow((1 + r), (-n))));
//@param p float Amount borrowed
//@param r interest, as a percentage
//@param n term in years
function calculateMortgage(p, r, n) { //setting function for mortgage calculator
//converting this percentage to a decimal
var r = percentToDecimal(r);
//convert years to months
n = yearsToMonths(n); //parameters set for n = conversion of years to months
//convert data with formula for obtaining monthly payments
var pmt = (r * p)/(1 - (Math.pow((1 + r), (-n))));
return parseFloat(pmt.toFixed(2));
return monthlyPayments; //returning to variabale monthly
}
function percentToDecimal(percent) { /
return (percent/12)/100; //assigning calculation for conversion of input
}
function postPayments(payment) {
var htmlEl = document.getElementById("outMonthly");
htmlEl.innerText = "$" + payment;
}
function yearsToMonths(year) { //function setup for converting year to months
return year * 12; //assigning calculation for years to months
}
var btn = document.getElementById("btnCalculate");
btn.onclick = function calculateMortgage(p, r , n) {
var cost = document.getElementById("inCost").value; //declaring variables for cost
var downPayment = document.getElementById("inDown").value;
var interest = document.getElementById("inAPR").value; //declaring variable for intrest
var term = document.getElementById("inTime").value; //declaring variable for term
var amountBorrowed = cost - downPayment; //declaring varibales for amount borrowed
var pmt = calculateMortgage(amountBorrowed, interest, term);
postPayments(pmt);
}
//console.log(cost, downPayment, interest, term);
//console.log("R", p); //call out log for para p
//console.log("R", r); //call out log for para r
//console.log("R", n); //call out log for para n
실례합니다. 여기에 멍청한 놈입니다. 학교에서 처음으로 이것을 배우십시오. 조심스럽게 "나는 넣어야한다 : jt의 세부 정보를 htl 페이지의 맨 아래에 넣는다. ... – simpleWebGuy
도움을 주셔서 감사합니다. 코드를 수정하는 데 도움이되었습니다. – simpleWebGuy