You can do the following:
var images = [
'http://my.site.com/img1.jpg',
'http://my.site.com/img2.jpg',
'http://my.site.com/img3.jpg',
'http://my.site.com/img4.jpg',
'http://my.site.com/img5.jpg',
'http://my.site.com/img6.jpg',
'http://my.site.com/img7.jpg',
];
function placeImage(id, images) {
document.getElementById(id).innerHTML = [
'<img src="',
images[(new Date()).getDay()],
'"/>'
].join('');
}
placeImage('demo', images);
Some Enhancements
- Placing array of image sources outside the function will prevent recreation of array each time function is called
- Using function parameters make it more generic and allow to populate for example another image container or take images from another source
[...].join('')
is kind of string buffer that for old browsers may provide better performance