Issue
I am thinking of something like this:
let img_1 = "./img/image.png";
let player = 1;
document.getElementById("player_img").src = "img_" + player;
then it can display ./img/image.png on the webpage
but the code above does not work, what is the right code?
Solution
Probably the best approach is use an array.
Like this
let img_ = ["./img/image.png","./img/image.png","./img/image.png"];
let player = 1;
document.getElementById("player_img").src = img_[player - 1];
Answered By - Jacopo Bonomi Answer Checked By - Robin (PHPFixing Admin)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.