re factored code for if-else-js.html