Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

135
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda