It's better to do the type-checking up front, as you did in Question 4. Otherwise you're doing the numeric comparisons above on something that might not be a number, leading to unexpected results.