An orientable manifold of codimension 1 is the zero set of a differentiable function I want to solve the following exercise from M. Spivak's Calculus on Manifolds:

If $M \subseteq \mathbb{R}^n$ is an orientable $(n-1)$-dimensional manifold, show that there is an open set $A \subseteq \mathbb{R}^n$ and a differentiable $g:A \to \mathbb{R}^1$ so that $M=g^{-1}(0)$ and $g'(x)$ has rank 1 for $x \in M$. Hint: Problem 5-4 does this locally. Use the orientation to choose consistent local solutions and use partitions of unity.

I don't understand why the orientation part is necessary. Once we express $M$ locally as the zero set of a function, why can't we just extend directly with partitions of unity?
EDIT:
Looking at Ted Shifrin's answer here we can represent $M$ as a zero set of some differentiable function without using any orientation argument.
Thank you!
EDIT2:
Now, I understand why the orientability part is important: If we have a differentiable function $g$ which defines $M$ as $g^{-1}(0)$ which has rank $1$ on $M$, then $\nabla g/\|g\|$ would give a continuous unit normal field, which can induce an orientation for $M$.
What I'm still having difficulties understanding is how to actually use a partition of unity to get a global result, and in particular, how can you guarantee that $M=g^{-1}(0)$ exactly? (the inclusion $g^{-1}(0) \subseteq M$ doesn't seem to be trivial)
Thanks again!
 A: Let $\{U_\alpha\}$ be an open covering of $M$ and $\{g_\alpha:U_\alpha\to\mathbb{R}\}$ functions defining $M$ locally. The orientability guarantees that all $g_\alpha$'s can be chosen so that their gradients point to the same "side" of $M$. Without this condition, once you take partition of unity and sum all $g_\alpha$, you may get non-regular points.
More precisely: If $M$ is oriented there is a smooth non-vanishing normal vector field $N$ on the whole of $M$. When taking $g_\alpha$ like in the previous paragraph, we make sure that for each $\alpha$ we have $$\langle \nabla g_\alpha,N\rangle>0.$$Then we use a partition of unity and get a function $g$, whose gradient satisfies $$\langle \nabla g,N\rangle>0.$$In particular, the gradient does not vanish anywhere on $M$.
Edit: The use of the partition of unity is as follows. Let $\{\varphi_\alpha\}$ be a partition of unity subordinate to the covering $\{U_\alpha\}$. For every $\alpha$ we define$$h_\alpha:M\to\mathbb{R},\qquad h_\alpha(x)=\left\{\begin{array}{cl}\varphi_\alpha(x)g_\alpha(x)&x\in U_\alpha\\0&x\not\in U_\alpha\end{array}\right..$$It is not hard to verify that every $h_\alpha$ is differentiable. Then set $h=\sum h_\alpha$, and you got the function you desire.
The orientation allows us to choose all the $g_\alpha$'s such that whenever $p\in U_{\alpha_1}\cap U_{\alpha_2}$, the values $g_{\alpha_1}(p)$ and $g_{\alpha_2}(p)$ have the same sign. Hence, for any $p\not\in M$, $h(p)$ is a convex combination of non-zero numbers, all having the same sign. This shows $h^{-1}(0)\subset M$.
A: As he says in the hint, you use orientation to choose CONSISTENT local solutions on which you can use partitions of unity.
The reason we need a consistent choice can be seen by thinking of an example.  Consider the Moebius Band.  If you make a local choice and use partitions of unity to pass the local choice around the band, you will eventually reach a point where you have made a local choice that does not agree with a local choice you have already made.  This image, I think, clarifies the point I am trying to make.
