0

Can someone explain me how this code snippet works?

I'm getting confused at {text += "<li>"} this part. text has been assigned the value of (<ul>) so does that mean each time the loop iterates (<ul>) will also get added multiple times? Please tell me where I'm going wrong! https://code.sololearn.com/W2ixq6wudkFU/?ref=app

23rd Aug 2020, 2:26 AM
Pawan
Pawan - avatar
4 odpowiedzi
+ 1
Variable <text> is getting concatenated with the <li> ... </li>. Add a log in console after the loop to see this ... console.log(text);
23rd Aug 2020, 5:25 AM
Ipang
+ 1
Pretty close there 👍, except for the <ul>, it is the first value of variable <text>. During the loop, only <li> ... </li> are concatenated to <text>.
23rd Aug 2020, 4:45 AM
Ipang
+ 1
But i don't understand why the var text is not getting concatenated with <li> ...</li> every time the loop iterates as they are in the same code block { }. What tells the loop not to iterate the var text ?Ipang
23rd Aug 2020, 5:21 AM
Pawan
Pawan - avatar
0
From my perspective I'm reading it like this every time the loop iterates (as x += y is same as x = x + y) <ul> <li> Banana</li> <ul> <li> Orange </li> <ul> <li> Apple </li> <ul> <li> Mango </li> </ul>
23rd Aug 2020, 2:37 AM
Pawan
Pawan - avatar