'i am to make my javascript keep a random image from my image folder, after writing all the codes the image is not showing and i don't know why
var randomNumber1 = Math.floor(Math.random()*6) + 1;
var diceName = "images/dice" + randomNumber1 + ".png"
document.querySelectorAll("img")[0].setAttribute("src", "diceName")
Solution 1:[1]
You are setting a string literal to src attribute.
remove quotes from "diceName".
document.querySelectorAll("img")[0].setAttribute("src", diceName)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Iftikhor |
