Please help me with the code below

IMHO starting with a simple script at first is a good idea. That’s how I prefer to work up a script. Working - tweak until it breaks - fix - rinse, repeat.

Notice the getImageSourceByDate() and the return lines.

The getImageSourceByDate() line is “calling” a function named “getImageSourceByDate”, but your code (as it is) has no such function.

If you open your browsers dev tools console you may see an “undefined” error message that could help point you to the problem.

Sometimes functions only “do stuff” without returning anything (void) but very often they return something be it an Int, String, Array, etc.

In this case, what you have should work if you wrap the code inside a function. i.e.

function getImageSourceByDate() { // new open curly brace
var date = new Date(); 
. 
. 
. 
else { 
  return 'image2.jpg'; 
}
}  // new closing curly brace