This question relates to Javascript.
What is the simplest way to modify the code below so that it keeps asking for the user to enter the correct value if the user enters an incorrect response. At the moment the code willaccept empty that the user enters nothing. Please show me how to fix this. Please keep it simple because I am new to coding.
const VALID_TEAMS =
["Australia","New Zealand","South-Africa","Pakistan","Brazil","West
Indies"];
const MIN = 0;
const MAX = 30;
const TEAM_NUM = 6;
var score = 0;
var findTeam;
var team;
var i;
document.writeln("");
for(i=0;i<=TEAM_NUM;i++){
team =
prompt("enter the team");
findTeam =
VALID_TEAMS.indexOf(team);
if(findTeam>=0 &&
findTeam<=5){
document.writeln("");
document.writeln("");
score = prompt("enter the
score");
while(isNaN(score) ||
score<0 || score>30 || score %3 !=0){
score =
prompt("enter the score");
}
document.writeln("");
}
document.writeln("");
}
document.writeln("
| "+team+" | "+score+" |
");
instead of using for loop you should use while loop and add a condition to handle the case of incorrect team input to prompt user again to enter the team name.
below is the modified code :
const VALID_TEAMS = ["Australia","New Zealand","South-Africa","Pakistan","Brazil","West Indies"];
const MIN = 0;
const MAX = 30;
const TEAM_NUM = 6;
var score = 0;
var findTeam;
var team;
var i=0;
document.writeln("");
// changed for loop to while loop
while(i<TEAM_NUM){
team = prompt("enter the team");
findTeam = VALID_TEAMS.indexOf(team);
if(findTeam>=0 && findTeam<=5){
document.writeln("");
document.writeln("");
score = prompt("enter the score");
while(isNaN(score) || score<0 || score>30 || score %3 !=0){
score = prompt("enter the score");
}
document.writeln("");
}
// added else statement for the case of incorrect input
else{
team = prompt("enter the team");
}
i++;
document.writeln("");
}
document.writeln("");
here are some images:

if this answer helped you then please upvote and feel free to comment any queries.
thankyou !
This question relates to Javascript. What is the simplest way to modify the code below so...