+ 2

Why reading the innerHTML of the paragraph should not be converted into numeric to be able to divide it?

function fun() { var obj = document.getElementById("text") var n =obj.innerHTML; obj.innerHTML = n/2; } https://code.sololearn.com/Wq0iwqH2wp90/?ref=app

4th Jul 2017, 5:24 PM
El CHR of MRD
El CHR of MRD - avatar
1 Antwort
+ 3
because the division operator implicitly converts the string to integer. it also works with - and * but not + because that would already mean concatenation of strings yes that is javascript for you, super lenient high level language. but if u encounter some med level langs like me learning java, i always have syntax errors lol
4th Jul 2017, 5:28 PM
David Sebastian Keshvi Illiakis
David Sebastian Keshvi Illiakis - avatar