Why not working?

Hello, I am wondering why this is not working? https://codepen.io/lanszelot/pen/qEBOGYQ
17 Replies
ἔρως
ἔρως3mo ago
because the value is a string
13eck
13eck3mo ago
What's not working? What do you think it should be doing?
ἔρως
ἔρως3mo ago
he wants to show the value in decimal, binary and stuff but .value returns a string
13eck
13eck3mo ago
-# Dude, I'm trying to teach them #How To Ask Good Questions :p It's not like we should just tell them that line three should be
let dec = document.getElementById("quantity").valueAsNumber;
let dec = document.getElementById("quantity").valueAsNumber;
And be done. It's a teaching moment!
ἔρως
ἔρως3mo ago
oh, sorry
13eck
13eck3mo ago
😜
ἔρως
ἔρως3mo ago
the problem with that property is that it is pretty obscure if you look for the documentation, it's pretty hidden
13eck
13eck3mo ago
Really, though, the takeaway is that almost everything in HTML land is a string and if you want another data type you need to convert it in JS
ἔρως
ἔρως3mo ago
yup next time, i will hold on my horses and not answer before the question is properly written
13eck
13eck3mo ago
Nah, it's all good. I know most people don't read the pinned message before posting >_< If we waited for a well-formed question nothing would ever get answered 🤣 😭
ἔρως
ἔρως3mo ago
luckly, this one was pretty obvious and the code wasnt 50000 lines long
lanszelot
lanszelotOP3mo ago
I thought if in HTML I add the input type as number the value will be number not string
ἔρως
ἔρως3mo ago
it's always a string always from js side
13eck
13eck3mo ago
The value property of the HTMLInputElement interface represents the current value of the <input> element as a string.
MDN docs In HTML, everything's a string
lanszelot
lanszelotOP3mo ago
I see, thank you
ἔρως
ἔρως3mo ago
that's why the number field has this property

Did you find this page helpful?