This conundrum is a common issue students encounter when working with functions and domain for the first time. It's a symptom of the fact that we don't properly define what a function is from the start:
A function in mathematics is a relation, $f$, between a set, $X$, called the domain, and a set $Y$ called the codomain, such that each element of the domain ($\forall x \in X$), is related to exactly one corresponding element of the codomain $f(x)=y\in Y$.
(A relation, $R$ is merely a subset of the Cartesian product of a domain with a codomain $R\subseteq X\times Y$, which we view as an association between (some) elements of the domain, $X$, and (some) elements of codomain, $Y$. An $x\in X$ may be associated to more than one $y$ or none at all, likewise, for a given $y\in Y$, it may be associated to one or more $x$'s or none at all).
As a sidenote: If you've ever wondered what $f$ itself is, it's actually the set of ordered pairs, $(x,y)$ that specify the associations between each domain element and it's unique corresponding codomain element. The expression $f(x)$ actually denotes what's known as the image under $f$ of the domain element $x$ (i.e. the corresponding $y$ in the codomain).
This proper definition and attendant concepts are glossed over, or avoided entirely when functions are first introduced, and that pedagogical mistake (imo) comes home to roost when they are then asked about domain (and range, not to be confused with codomain; they are related but not the same thing).
Worse yet, in familiar contexts, there is a usually unmentioned convention for denoting functions that is taken. Since one is often interested in functions between the real numbers and itself, or between a subset of the real numbers and the real numbers, and these sets are (usually) all infinite. There exists a bit of a problem in how exactly we hope to capture exactly where each and every domain element is mapped to in the codomain? This is usually handled by the use of a rule of assignment which specifies how we can obtain the unique codomain element $f(x)$ specified by a given choice of a domain element $x$. Familiar examples such as $f(x)=x+3$ and $f(x)=x^2$ and many more are examples of such rules of assignment. These familiar examples use arithmetic operations and (later) other well understood functions to specify the corresponding codomain element for every possible domain element. Some of our arithmetic rules are not defined everywhere in the reals though, for instance one cannot divide by $0$, or take a square root of a negative number (and remain in the reals, at least) etc. Because of this, rules like $1/x$ do not make sense over all of $\mathbb{R}$, thus the convention is that the domain for functions specified by a rule of assignment is the largest possible subset of the reals for which that rule makes sense (or in more formal language: for which that rule is definable). Hence the task that is actually being asked of beginning algebra students is to deduce the largest subset of the reals for which a given arithmetic expression (that is the given function's rule of assignment) actually makes sense. That is the conventionally defined domain of that function.