Issue with conditional logic not result to expected answer?