deutschprincess
09-22-2005, 12:30 AM
Ok- I have three arrays, and then I have a function generate a random number for a variable in the array. Then it puts it together in a word. It's for a random name generator, by the way. The problem is that sometimes everything works fine and I get a nice word made from 3 random parts of the array, but sometimes one of the parts comes up as undefined. Can anybody help? Here's some of the coding, shortened:
// 1st List Values
list1=new Array(3);
list1[1]="Mar";
list1[2]="Lis";
list1[3]="Ann";
// 2nd List Values
list2=new Array(3);
list2[1]="kai";
list2[2]="ie";
list2[3]="";
// 3rd List Values
list3=new Array(3);
list3[1]="la";
list3[2]="se";
list3[3]="eve";
function gen_name()
{
var v1;
var v2;
var v3;
var v4;
var x1;
var y1;
var z1;
x1=Math.floor(Math.random()* 3) + 1;
y1=Math.floor(Math.random()* 3) + 1;
z1=Math.floor(Math.random()* 3) + 1;
fantasyname.innerText=list1[x1] + list2[y1] + list3[z1];
(this little bit from the var v1 to the fantasyname.innerText part is repeated several times, and it's the same except for 'fantasyname2, 3, 4, 5' etc. Then later on it outputs that number of names.)
Sorry if I'm explaining really badly or I am just being a total noob here... I'm new to Javascript, obviously. At this point I have no idea what I could be doing wrong so help is extremely appreciated. Thanks. :)
// 1st List Values
list1=new Array(3);
list1[1]="Mar";
list1[2]="Lis";
list1[3]="Ann";
// 2nd List Values
list2=new Array(3);
list2[1]="kai";
list2[2]="ie";
list2[3]="";
// 3rd List Values
list3=new Array(3);
list3[1]="la";
list3[2]="se";
list3[3]="eve";
function gen_name()
{
var v1;
var v2;
var v3;
var v4;
var x1;
var y1;
var z1;
x1=Math.floor(Math.random()* 3) + 1;
y1=Math.floor(Math.random()* 3) + 1;
z1=Math.floor(Math.random()* 3) + 1;
fantasyname.innerText=list1[x1] + list2[y1] + list3[z1];
(this little bit from the var v1 to the fantasyname.innerText part is repeated several times, and it's the same except for 'fantasyname2, 3, 4, 5' etc. Then later on it outputs that number of names.)
Sorry if I'm explaining really badly or I am just being a total noob here... I'm new to Javascript, obviously. At this point I have no idea what I could be doing wrong so help is extremely appreciated. Thanks. :)