while-loopbulletedlist

array using a while loop to display in a bulleted list


I am very new to Javascript and am trying to recreate the following code using a While loop instead of a For loop. I can get it to list but not in an unordered list. Any help would be much appreciated.

var middle = "Wayne";
var streets = ["Elm Street", "Sesame Street", "Coronation Street", "Jump 
Street", "Wall Street"];
var sLen = streets.length;
var text = "<ul>";
for (i = 0; i < sLen; i++){
text += "<li>" + middle + " " + streets[i] + "</li>";
}
text += "</ul>";
document.getElementById("nameList").innerHTML = text;

Solution

  • var i = 0;
    while(i<sLen){
       ...execution code goes here...  
       i++;
    }
    

    Please review this reference to learn more about while loops while-loops-Javascript