In my quest to select a killer from the Cast Members Array for the game, I want the function to pick one person as the killer and then remove them from the castMember player array.
Once the killer is chosen, they should be removed from the survivors array and stored separately as their own variable for future functions.
I attempted to achieve this using a for loop and splice method on the array, but unfortunately, it is not working as intended.
let episodes = 6; // Number of Episodes
let episodecount = 0; // Episode Count Value
let killer; // Initializes killer variable
let killerRevealed = false; // Initialize killerRevealed status
let stamina; // Stamina stat for each player
let speed; // Speed stat for each player
let strength; // Strength stat for each player
let suspicion; // Suspicion stat for each player
let highestPlayer; // Player with the highest stats
let castMembers = [
"Sidney Prescott",
"Gale Weathers",
"Stu Macher",
"Billy Loomis",
"Dewey Riley",
"Tatum Riley",
"Principal Himbry",
"Kenny Brown"
];
let gameStarted = false;
let objects = ["knife", "gun", "shovel", "rope", "candle", "matche", "lighter", "clothesline", "hiding spot", "clue"]; // List of objects
let events = ["sudden outburst", "false accusation", "heated argument", "suspicious behavior", "mysterious disappearance", "surprising discovery"]; // List of random events
let scenes = ["opening scene", "house party garage scene", "outside van scene", "high school scene", "house party living room", "house party attick"]
let playAs1996Cast = document.getElementById("buttonp")
let killerSet = false;
function getRandom(arr) {
return arr[Math.floor(Math.random() * arr.length)];
}
// Function to randomly select the Killer
function chooseKiller(){
let randomNumber = Math.floor(Math.random() * castMembers.length);
killer = castMembers[randomNumber];
console.log ("A new killer has been chosen: " + killer);
for (var i = 0; i < killer.length; i++){
if (killer[i].id == 1) {
killer.splice(i, 1)
break;
}
}