Add a dot in between the two String.replace calls, on the same line, like so:
if(params["This_year"] == "1/1/14"){
this.queryText = this.queryText.replace("/**year**/", "2014").replace("/**Last_year**/, "1/1/13"); }
The second call will modify the string returned by the first call.
My spider sense tells me that there's probably something about this that can be generalized into an algorithm, but without seeing more examples, it's hard to know what that would be.