Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

246
Views
how to set dynamic image in javascript?
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

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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">

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!