+ 2

In loops, anyone explain in details to me this line of code. document. write(i+ "<br>"); I understood the rest part just this 1

Loops in JavaScript

21st Sep 2017, 12:21 AM
Leonard Ojojo
Leonard Ojojo - avatar
8 odpowiedzi
+ 8
You should have tagged JavaScript on your question. I'm guessing it makes the value of i a string and concatenates the specified string together, giving "1<br />" through "5<br />". However, I haven't studied JavaScript as yet.
21st Sep 2017, 12:43 AM
John Wells
John Wells - avatar
+ 3
could you share entire code?
21st Sep 2017, 12:30 AM
Daniel
Daniel - avatar
+ 2
Thanks in advance
21st Sep 2017, 12:21 AM
Leonard Ojojo
Leonard Ojojo - avatar
+ 2
Here we go. for (i=1; i<=5; i++) { document.write(i + "<br />"); }
21st Sep 2017, 12:36 AM
Leonard Ojojo
Leonard Ojojo - avatar
+ 2
It is a loop to show numbers from 1 to 5, each one in a new line because <br/> at the end is to jump next line
21st Sep 2017, 12:38 AM
Daniel
Daniel - avatar
+ 2
OK what about the i+ in the bracket?
21st Sep 2017, 12:40 AM
Leonard Ojojo
Leonard Ojojo - avatar
+ 2
Thanks John
21st Sep 2017, 12:45 AM
Leonard Ojojo
Leonard Ojojo - avatar
+ 1
document.write(i + "<br>") i guess the part confusing you is the html break line tag<br>. that is just a way of telling the browser to display every new result in a new line. try removing the "<br>" (include the quotes) and see how everything would compact together
24th Sep 2017, 1:03 PM
Christian Onoh
Christian Onoh - avatar