Hi everyone, I’m doing this simple project ’ calculate percentage’, here is the link to my codepen: https://codepen.io/zaqxsw/pen/poyBLoW
I can’t find out why my function doesn’t work when I put in the input value.
p/s: I haven’t added any CSS.
Hello~!
At a first glance, I believe the issue is here:
function calculate (){
var inCome = document.getElementById("income").value;var people = document.getElementById("people").value;// input
if (inCome == 0) alert("Please enter values");
else if (people === ""){people = 1;}
else if (inCome <= 0 || people < 0 )
alert("fault values");
else return; //this line. Return ends a function.
1 Like
Those if statements definitely should get a little review, but the console (button is on the bottom left in codepen) tells you what’s the actual error:
TypeError: spendOnSaving.tofixed is not a function
(you just misspelled tofixed
)
2 Likes
Thanks a lot, I’ll take a look at my condition statement
Hi there, A big thanks to you. I’ll take a look at my condition statement like you say.