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

143
Views
I'm trying to make function randomly choose between the 2 images but nothing happens

the 2 images are uploaded in the coding program

Function getFoto() {
  var Foto = new Array();
Foto[0] = "image1.jpg";
Foto[1]=  "image2.jpg";

var Nummer =  Math.floor(Math.random()*Foto.length);
  return document.getElementById("result").innerHTML = '<img src="'+Foto[Nummer]+'" />';}   
getFoto()
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

As with all things in programming, learning to debug is essentially the primary skill you need to solving most problems. So in this situation I would first setup debugging in vscode and then look at the value you are passing in the math.Floor function. Then look at the value of Nummer. Then make sure Foto[that value of Nummer] works.

about 4 years ago · Juan Pablo Isaza Report

0

You make the function keywords to Function which will not be executed and parsed by JS.

function getFoto() {
  var Foto = new Array();
Foto[0] = "image1.jpg";
Foto[1]=  "image2.jpg";
   
var Nummer =  Math.floor(Math.random()*Foto.length);
console.log(Nummer)
  return document.getElementById("result").innerHTML = '<img src="'+Foto[Nummer]+'" />';
  }   
getFoto()
<div id=result></div>

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!