let stack1=document.querySelector("#stack1");
let randomNumber=Math.floor(Math.random()*52)+1;
stack1.src=`"card1/image_part_0${randomNumber}.jpg"`;
//there are 52 images and their names are in the format 'image_part_0n' where
// n can be any random number from 1 to 52
You are doing correct just remove "" from
stack1.src=`"card1/image_part_0${randomNumber}.jpg"`;
try it like this
stack1.src=`/card1/image_part_0${randomNumber}.jpg`;
because of " path is getting corrupt.
let stack1=document.querySelector("#stack1");
let randomNumber=Math.floor(Math.random()*52)+1;
stack1.src=`/card1/image_part_0${randomNumber}.jpg`;
console.log(stack1.src);
<img id="stack1" src="" alt="picture with dynamic path" width="500" height="600">