+ 2
JavaScript Help !!! ( won’t display nor calculate )
I Sucked at JavaScript and apparently I have no Idea what am doing. Where supposed to make a mortgage calculator where we input the property cost, deposit, principal, how long do you need to repay, annual interest rate and how many payment will you make each year and then you calculate the payment. Function calc() { const propertycost=document.queryselector(‘#propertycost’). value; const deposite=document.queryselector(‘#deposite’).value; const principal=(propertycost-deposite).value; I knw it’s wrong
2 odpowiedzi
+ 3
Your quotation marks or apostrophes are messed up like you copy/pasted them out of a Word-processor.
It is querySelector and not queryselector. Get the case right because JavaScript is case-sensitive.
It is also function not Function for the same reason as above.
The word deposit has no e at the end but this won't stop any JavaScript from working. I won't fix that spelling below because this fix extends to your HTML which would have an id="deposite" attribute.
Here are all the above corrections made.
function calc()
{
const propertycost=document.querySelector('#propertycost').value;
const deposite=document.querySelector('#deposite').value;
const principal=(propertycost-deposite).value;
}
+ 2
Further to Josh Greig 's answer,
there are two more error to fix.
Firstly the returned value of input box are String, and you cannot perform mathematical deduction on String, it will result in NaN (not a number).
So you should
propertycost = Number(propertycost);
same for deposite.
Secondly, you don't need to use .value when performing mathematical deduction, reason is that you are using two numbers already.
You use .value only when you need to extract value from a input box.