+ 2
JavaScript is the hardest language i ever study.
Dear friends and my loving follower's, i know about c++, Java, Html, Css; but i have never get this type of trouble as in JavaScript although i write everything correct but still the output alway's come either nothing or NaN . for Example: https://code.sololearn.com/Wihzb2fUM40B/?ref=app
11 odpowiedzi
+ 3
@Splitty can you make the correction in my coding
and send it too
+ 3
but way the loop is not working @Splitty
+ 3
for example if i enter 5 it would so the result
as in this
https://code.sololearn.com/WHIvFnZj7824/?ref=app
+ 3
@Splitty i able to make it by using document.write
but why it is not working in innerHTML=
https://code.sololearn.com/WxKQf2uK5q55/?ref=app
+ 3
thanks bro i understand.
+ 3
thats WORK @Splitty
https://code.sololearn.com/WIAb173CDJ12/?ref=app
+ 1
a is a HTMLInputElement, not an integer. You can't compare a to i. What you probably want is while (i < Number(a.value))
+ 1
There you go:
https://code.sololearn.com/WkM7908Gej6P/?ref=app
+ 1
foo.innerHTML = "bar" sets the HTML content of foo to bar. It's like if you're writing:
<foo>bar</foo>
Now if you set innerHTML in a loop again, it just overrides the HTML content with the same text. So the text doesn't change.
If you want it to change, you can do the following:
foo.innerHTML += '<br>' + text
Or in your case:
document.getElementById('dem').innerHTML += "<br>hello";
Now you are adding to the inner HTML instead of replacing it.
0
What do you mean? The loop is working. Hello is written, and i is incremented.
0
You are setting innerHTML, which overrides the text that was previously there. You can use innerHTML += instead of = if you want to append the text.