Hey y’all,
I’ve double checked my syntax several times and i still can’t seem to figure out why my code isn’t working for this dice game I’m making with javascript. Any help is appreciated!
var randomNumber1 = Math.floor(Math.random()*(6) + 1);
//console.log(randomNumber1);
//let randomNumber2 = Math.floor(Math.random()*(6) + 1);
//console.log(randomNumber1);
var randomDiceImage = "images/dice" + randomNumber1 + ".png";
let image1 = document.querySelectorAll("img")[0]; //.setAttribute('/images.randomDiceImage');
// document.querySelector("img").setAttribute('/images.dice4.png');
image1.setAttribute("src", randomDiceImage);
Here are the two errors I get:
VM61146 index.js:14 Uncaught TypeError: Cannot read property ‘setAttribute’ of undefined
at VM61146 index.js:14
(anonymous) @ VM61146 index.js:14
index.js:1 Uncaught SyntaxError: Identifier ‘image1’ has already been declared