Amended JS in order for the if/else statment to work correctly