Recently delving into the world of JavaScript, I encountered a peculiar issue. When attempting to execute the following code within a function, nothing displays in the console. Yet, after testing it without the function, the expected strings appear as intended. Is there a way to integrate this code with a function or are there other adjustments required?
JavaScript:
function randSong() {
var i = Math.floor(Math.random()*10);
var listOfSongs = ['Killomanjaro','No Sad No Bad','Doomsday','Solitaire',
'Distance','Roll In Peace','Bank Account','SAD!','Moonlight','Swimming Pools'];
console.log('Alexa, play',listOfSongs[i]);
}
Access the repl.it here:https://repl.it/@OoferGangx7/random-song-loop
UPDATE: An oversight on my part led to the confusion - simply forgot to call the function. Mystery solved!