Surrounding a fragment of JavaScript code with an if...else construct