i am not sure about the code .However if you use ternary operator ,it will be better .Just suggesting