I'm currently using w3schools for javascript. I've done some js work on freecodecamp but I came across something on w3schools that I'm not familiar with and would be nice if someone could explain to me why this works.
The text variable declares "ul", it is also used inside the for loop code block (if that's what you call it), and also used again after the for loop.
It clearly works but I can't get my head round it even though it seems so simple.
I know because it's a script tag and you can't directly use the html tags, but how does the computer know to use an unordered list, followed by list item when it's quoted in quotation marks. If that makes sense.
<script>
const fruits = ["Banana", "Orange", "Apple", "Mango"];
let fLen = fruits.length;
let text = "<ul>";
for (let i = 0; i < fLen; i++) {
text += "<li>" + fruits[i] + "</li>";
}
text += "</ul>";
document.getElementById("demo").innerHTML = text;
</script>