JavaScript is the hardest language i ever study. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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

25th Jan 2018, 8:31 AM
🦋FEATHER🦋
🦋FEATHER🦋 - avatar
11 Answers
+ 3
@Splitty can you make the correction in my coding and send it too
25th Jan 2018, 8:39 AM
🦋FEATHER🦋
🦋FEATHER🦋 - avatar
+ 3
but way the loop is not working @Splitty
25th Jan 2018, 8:45 AM
🦋FEATHER🦋
🦋FEATHER🦋 - avatar
+ 3
for example if i enter 5 it would so the result as in this https://code.sololearn.com/WHIvFnZj7824/?ref=app
25th Jan 2018, 8:47 AM
🦋FEATHER🦋
🦋FEATHER🦋 - avatar
+ 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
25th Jan 2018, 8:55 AM
🦋FEATHER🦋
🦋FEATHER🦋 - avatar
+ 3
thanks bro i understand.
25th Jan 2018, 9:11 AM
🦋FEATHER🦋
🦋FEATHER🦋 - avatar
25th Jan 2018, 9:19 AM
🦋FEATHER🦋
🦋FEATHER🦋 - avatar
+ 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))
25th Jan 2018, 8:37 AM
SplittyDev
SplittyDev - avatar
25th Jan 2018, 8:43 AM
SplittyDev
SplittyDev - avatar
+ 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.
25th Jan 2018, 9:06 AM
SplittyDev
SplittyDev - avatar
0
What do you mean? The loop is working. Hello is written, and i is incremented.
25th Jan 2018, 8:45 AM
SplittyDev
SplittyDev - avatar
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.
25th Jan 2018, 8:49 AM
SplittyDev
SplittyDev - avatar