Javascript not working with dice game

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

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

Did you already declare the image1 variable somewhere before this part of the code? The error seems to suggest you did.

You can not re-declare variables created using let.

let test;

// Uncaught SyntaxError: Identifier 'test' has already been declared
let test = 'test';