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?
CodePudding user response:
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];