I have the following code repeated in 3 different places:

var el = document.getElementById("mydiv");
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