New to JavaScript. I'm trying to create an extremely basic mortgage calculator as my first small JavaScript project. The idea is to display the monthly cost of a mortgage payment.
I'm not getting any errors at the moment. The console.log is showing the correct answer, but I want it to be displayed in the box next to the submit button. I cannot find a way to display the result of the calculation in that box. I've scoured the internet and I'm racking my brains over how to do it. Any help is very much appreciated.
Here's my code:
HTML
<form action="">
<input type="number" id="amountBorrowed" placeholder="Amount Borrowed">
<input type="number" id="mortgageTerm" placeholder="Term in Years">
<input type="button" id="sub" value="Submit" onclick="mortgageCalc()">
<input type="number" id="monthlyCost" name="monthlyCost">
</form>
JavaScript
function mortgageCalc() {
var amountBorrowed;
var mortgageTerm;
var monthlyCost;
amountBorrowed = document.getElementById("amountBorrowed").value;
mortgageTerm = document.getElementById("mortgageTerm").value;
mortgageTerm *= 12;
monthlyCost = (amountBorrowed / mortgageTerm);
console.log(monthlyCost);
}
Thanks a lot.