José Ignacio Asked: 2020-02-13 13:39:37 +0800 CST 2020-02-13 13:39:37 +0800 CST 2020-02-13 13:39:37 +0800 CST Where should I put the alert in this Do While loop to display the "Wrong Password" message? 772 let pass = "ED"; let password; do{ password = prompt("Introduzca la contraseña"); } while (password != "ED"); javascript 2 Answers Voted Best Answer Asier Villanueva 2020-02-13T13:46:40+08:002020-02-13T13:46:40+08:00 You could put it, for example, before asking for it if the user has already entered one: let pass = "ED"; let password; do{ if (password) alert('Contraseña incorrecta'); password = prompt("Introduzca la contraseña"); } while (password != pass); Albert Hidalgo 2020-02-13T13:46:27+08:002020-02-13T13:46:27+08:00 Something that occurs to me is: let pass = "ED"; let password; do{ password = prompt("Introduzca la contraseña"); if(password != "ED"){ alert('Contraseña incorrecta'); } } while (password != "ED"); It will stay in the loop as long as the key is wrong.
You could put it, for example, before asking for it if the user has already entered one:
Something that occurs to me is: