I recently wrote a Javascript code to display a list of items, but for some reason an unexpected undefined
text is appearing before the ordered list. I am quite puzzled as to why this issue is occurring.
I am wondering if there is a variable that has not been defined correctly or perhaps inserted in the wrong way within this particular block of code?
You can also view the demo on JSBIN. (Additionally, here is an alternative method to write the code with the same objective.)
var playList = [
"First Life",
"Spaceman",
"Run run run"
];
function print(message) {
message += "<ol>";
for (var i=0; i<playList.length; i+=1) {
message += "<li>" + playList[i]+"</li>";
}
message += "</ol>";
document.write(message);
}
print();