I'm trying to create an array from a for loop. Once the array is created I need to pick a random value in the array to display. In this case the values are pictures 1-4.png. I'm running into some trouble because the array looks like it's not being created, console says "Cannot set property 'src' of null".
var imgstart = 1;
var imgend = 4;
var arrimg = [];
for (var i = imgstart; i < imgend+1; i++) {
arrimg.push(i)
}
window.onload = choosePic;
function choosePic() {
var randomNum = Math.floor(Math.random() * arrimg.length);
document.getElementById("myPicture").src = arrimg[randomNum] + '.png';
}
<img id="myPicture" />