0
<script>
f = new Array();
f.push('h');
f.push('a');
f.push('i');
f.push('l');
f.push('e');
f.push('r');
f.push('i2');
f.push('s');
t = f.length;
face = f[Math.floor(Math.random() * t)];
document.getElementById('img').innerHTML = '<img src="' + face + '.png" alt="something" />';
</script>

It does not work i am trying to make an array that randomize the images and shows them to the user, but it is not working and i dont know why

1 Answers1

0

It appears the answer here was to make sure the code was being run after page load

<body>

...

<script>
  f = new Array();
  f.push('h');
  f.push('a');
  f.push('i');
  f.push('l');
  f.push('e');
  f.push('r');
  f.push('i2');
  f.push('s');
  t = f.length;
  face = f[Math.floor(Math.random() * t)];
  document.getElementById('img').innerHTML = '<img src="' + face + '.png" alt="something" />';
</script>

</body>
Nick
  • 16,066
  • 3
  • 16
  • 32