JavaScript: Function with if else(Right and Wrong)