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
4 Respostas
+ 1
Variable <text> is getting concatenated with the <li> ... </li>.
Add a log in console after the loop to see this ...
console.log(text);
+ 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>.
+ 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
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>