Reputation: 37
let h;
function getRandomIntH() {
return Math.round(Math.random() * 250);}
h = getRandomIntH();
$('#gamespace').append('<img src="transparent.gif" style="left: 100px; top: h; width: 100px; height: 100px;">');
I made a function above that makes a random number, but whenever I try and use it to move my image, it inputs as zero instead of the number stored in the variable.
Upvotes: 0
Views: 35
Reputation: 451
Replace the last line with this so that you're using the value from the h variable instead of setting top to the string "h":
$('#gamespace').append(`<img src="transparent.gif" style="left: 100px; top: ${h}px; width: 100px; height: 100px;">`);
Upvotes: 1