I want to create a while loop to avoid empty input. Here's my code, I want it to loop so that the user gets the same alert and then prompt window until he/she writes a name/username. Any ideas on what I'm doing wrong and how to fix it?
<script type="text/javascript">
confirm("Wanna play?");
var name = prompt("What's your name?");
while (name.length == 0) {
alert("Please enter your name!");
prompt("What's your name?");
}
else {
document.write("Welcome to my game " + name + "!" + "<br>");
}
</script>