in javascript return statement only used inside function block. if you try to use return statement inside independent if else block it trigger syntax error : Illegal return statement in JavaScript
Here is my example code to avoid such error :
Please check Jsfiddle example