Confusion about range of integration for density function Consider the joint density function:
$$f(x,y) = \begin{cases}
2  & & \text{for } 0 \leq x \leq1 \text{ and } 0 \leq y \leq 1-x, \\[6pt]
0 & & \text{otherwise}. 
\end{cases}$$
From this joint density I figured out the following marginal densities:
$$f_X(x) = 2(1-x),\\
f_Y(y) = 2.$$
The marginal density $f_Y$ is supposedly wrong, as the solutions provided to me say to calculate $\int^{1-y}_0 2 \, dx$.  I don't see why I need to integrate over $[0, 1-y]$ and not over $[0,1]$.  I thought the range for $x$ does not depend on $y$, or does it?
 A: Comment: I simulated the joint distribution as an easy way to make the plot
suggested in a previous comment. Before beginning to set limits on double
integrals it is usually a good idea to sketch such a picture as a guide.
I have shown R code for the first of the three plots.
set.seed(1218); m = 10^5
x1 = runif(m);  y1 = runif(m)
cond = (y1 <= 1 - x1)
x = x1[cond];  y = y1[cond]
plot(x, y, pch=".")


The simulation and plots are for orientation, and are not an exact solution to your problem. For exact solutions, maybe the first thing to do is to try to integrate the joint density $f(x,y) = 2$ over the triangular region to make sure the integral is $1,$ as required for
a density function. 
Then try integrating over $x$ to find the marginal density of $Y,$ which is
suggested by the red line superimposed on the histogram in the third plot.
A: You wrote:
$$
\text{for } 0 \leq x \leq1 \text{ and } 0 \leq y \leq 1-x
$$
That tells you the region over which you integrate.
You want to integrate out $x$ with $y$ fixed.
So you need those values of $x$ for which $0\le x\le1$ and $0\le y \le 1-x.$ Notice that $y\le 1-x$ is equivalent to $x \le 1-y.$
