I have the following code repeated in 3 different places:

var el = document.getElementById("mydiv");
el.innerHTML=caption[i];
var img= document.getElementById("slide");
img.src= image[i];

I'm wanting to take the above code, move it into a function such as setCaption() and setImage(), and call those functions where I have the repeated code. Need help with what this should look like

Thanks