When I put the while loop in like this, my background and my prompts never show up. I have no clue on why would be causing this. Everything else works to perfection, it is just once I add the while loop my code breaks. I have tried a for loop as well but it also does not work.
//score
var score = 0
//replay loop
var replay = "yes"
//name of each gen 1 pokemon
var pname = ['#']
//images for each one
var bg = ['#']
while (replay == 'yes'){
background = bg[num = Math.floor(Math.random() * bg.length)];
document.body.style.backgroundImage = 'url(' + background + ')';
setTimeout(() => {
var answer = prompt("What pokemon is this?")
if (answer.toLowerCase() == pname[num].toLowerCase()) {
alert("correct")
score ++
replay = prompt("Want to keep playing?")
} else {
alert("incorrect")
replay = prompt("Want to keep playing?")
}
}, 2000);
}