mercredi 1 mars 2023

How to get the value of a function to use on end of GetElementByID.SRC

I've got a function that picks a random image out of the three in the array, however I want to display one of the 3 images randomly at the end of the GetElementByID.SRC code so it randomly picks a picture and shows it.

I'm struggling to see why this isn't working as I've read other things online that have led me to this.

enter image description here

The image above is what I'm getting, but the sources are correct from what I can tell.

enter image description here

// Function to play each episode
function playEpisode() {

let lowestPlayer = 0;

for (let i = 0; i < players; i++) { // Loop through each player 
    let totalStats = stamina + speed + strength; // Calculate total combined stats
    if (totalStats < lowestPlayer) { // Compare total combined stats to the lowest score and update if needed
        lowestPlayer = totalStats;
        break;
    }
}

let lowestPlayerCastMember = castMembers[lowestPlayer];
let randomSceneNumber = Math.floor(Math.random() * scenes.length);

gameStarted = true;

var img = ["./images/s1oc.webp", "./images/garagekill.gif", "./images/highschoolmurder.gif"]

function imgRandom (imgArr) {
    
    return imgArr[Math.floor(Math.random(img) * imgArr.length)];
}

document.getElementById("mainbox").innerHTML = scenes[randomSceneNumber];
document.getElementById("scenebox").src = imgRandom(img);
document.getElementById("desc").innerHTML = "The Phone Rings at " + lowestPlayerCastMember + " answers the phone";

assignObjects();
triggerEvent(); 
eliminateOne();
removeDeadCast();
increaseSuspicion();    
episodecount++; // Increment episode count

console.log("Episode after Opening Scene Count " + episodecount);
}

Expected it to work, but it doesn't and there's no sign of issue.

EDIT: I HAVE CHANGED THE SCRIPT AS I'VE FIXED IT NOW - The file format was wrong and not added to the array and the Math.random was written in lowercase for the M.




Aucun commentaire:

Enregistrer un commentaire