Im trying to code a random houses generator in JS for a game of thrones game, the code looks like that at the moment:
//Houses Array:
var HousesArray = [
'Stark',
'Lanister',
'Greyjoy',
'Barathion',
'Arryn',
'Tyrell',
'Martell',
'Targaryen'
];
//Houses Variables:
var house1 = {}
var house2 = {}
var house3 = {}
//Random House Generator
var RandomIndex = Math.floor(Math.random()*HousesArray.length)
var RandomElement = HousesArray[RandomIndex]
//3 Players Generator:
house1 = RandomElement
console.log(house1)
HousesArray.splice(house1,1)
RandomElement = HousesArray[RandomIndex]
house2 = RandomElement
console.log(house2)
HousesArray.splice(house2,1)
RandomElement = HousesArray[RandomIndex]
house3 = RandomElement
console.log(house3)
What I tryed to do here is to give the house1 variable a random house name from one of the HousesArray Eelements, echo that to the console log, then remove the selected element from HousesArray using the splice commend (to ensure that the next selection will not be the same one). after all that - generate new house name from the elements left in the HousesArray and repeat. But for some reasos, Every time house1 = "Targaryen" (or house2) the next 2/1 resolts automaticly return "undifined" (I beleive its becuse the "Targaryen" element is the last in the list)
How can i fix that?