Sololearn: Learn to Code
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3
The¥AIRWeb try this: alert("Designed by Air Philippines"); var user = prompt("Name"); confirm(user); var passed = false var email = prompt("Email"); while(passed===false){ if (email!=null && email.includes("@")){ passed = true confirm(email); alert("Thanks!"); } else if(email===null){ break } else{ email = prompt("Invalid. Please include @ ") } } console.log(.......)
22nd May 2022, 8:59 AM
Bob_Li
Bob_Li - avatar
+ 3
The¥AIRWeb how about this? alert("Designed by Air Philippines"); var user = prompt("Name"); confirm(user); var passed = false while(passed===false){ var email = prompt("Email"); if (email.includes("@")){ passed = true confirm(email); alert("Thanks!"); } else{ email = prompt("Invalid. Please include @ ") } } console.log(.......)
22nd May 2022, 3:55 AM
Bob_Li
Bob_Li - avatar
+ 1
You can't use else if without if.
21st May 2022, 3:20 AM
Simon Sauter
Simon Sauter - avatar
+ 1
var user = prompt("Name"); if (user == null) { alert("Please enter your name"); }
21st May 2022, 3:25 AM
SoloProg
SoloProg - avatar
+ 1
the error occurs when you click the cancel button, which returns null and assigns null to email.
22nd May 2022, 8:48 AM
Bob_Li
Bob_Li - avatar
21st May 2022, 3:46 AM
Simon Sauter
Simon Sauter - avatar
0
You don't need else... If Just one condition and one counter condition so use if... else
23rd May 2022, 1:52 AM
Mikeey
Mikeey - avatar
0
Use if else .... For better validation
23rd May 2022, 2:05 AM
Mikeey
Mikeey - avatar