Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

how to compare the ids in an array to each other when the user is still entering the values of each ID[i]?

i have this code that creates a table and asks the user to enter the values of IDs and makes sure that the id is a number and breaks if the user inputs it 3 times not a number and prevents the user to input an id number that already exists

i only need some help on how to prevent the user all i got out with is just compering the ID[i] with one previous value and not all the previous values

<script>

var i;

var j;

var w;

var con=0;

var ID=new Array(5);

var grade;

var sum=0;

var names=new Array(5);

names[0]="Duaa";

names[1]="Chaza";

names[2]="Ola";

names[3]="Ghina";

names[4]="Hassan";

document.writeln("<table border='1'>");

for(i=0;i<names.length;i++)

{

con=0;

ID[i]=prompt("Enter The Id number of "+names[i],"ID number");

while(isNaN(ID[i])&&con<2)

{

con++;

ID[i]=prompt("Enter The Id number of "+names[i],"ID number");

}

/* This loop */

for(w=0;w<ID.length;w++)

{

if(ID[i]==ID[i-1])

{

window.alert("You Have Already Entered That Id Number!");

break;

}

}

if(con==2)

{

window.alert("You are a loser!");

break;

}

else

{

/*other details and stuff i'm already done with */

}

}

1 Answer

Relevance
Still have questions? Get your answers by asking now.