#Self made JS calculator not displaying values, just NaN
24 messages · Page 1 of 1 (latest)
sorry, i had it moved in the updated version. Now it's undefined
thanks for the help thus far
@fleet ember any idea thx
have you tried debugging with devtools?
i have not, im a little new so ive just been toying in codepen
is it better to pull it into vscode?
nah, just open devtools (right click and "inspect"), add a debugger; (javascript keyword for setting a hardcoded-debug-breakpoint) somewhere near where you set the result and run it by clicking "calculate"
it'll let you inspect all the different variables by hovering over them with the mouse cursor
like you are using html elements as if they were integers, thats not how that works
so i can't just create a div and use its id to send an integer val?
no, they are mere handles to DOMElements, though they are objects that are designed to give you every bit of info and interaction you could ever want from them
you set variables called heightNum and lengthNum in the beginning, just add .value ad the end of the getElementById() calls and don't forget to wrap the entire thing in a parseInt to convert the returned string in .value to an integer
parseInt() won't work so well for fractions 😉
or Number()
I'm still getting a NaN error.
perhaps .innerText isn't the right function for a float var?
log it and see?
oh, to assign the result? you can pass a number just fine. that's not what's giving you NaN
you're calling parseFloat(lengthValue) and parseFloat(heightValue) 1000 times. why not just assign the parsed number to lengthValue and heightValue from the start?
your issue is you're assigning .value to those variables when your script loads, not in the click handler