You have declared the y variable inside the if statement therefore you cannot access outside the if statement.