There are many ways to parameterize this problem, and many different approaches.
First of all, generalize the dimensions of the box to r × s; see below. For an approach that does not necessarily use calculus, let the distance above the box at which the ladder touches the wall be x, and let the corresponding horizontal distance be y. Let the ladder have length d.
Show that y = rs/x. Hence derive a polynomial equation in x, with coefficients involving r, s, and d. When will this equation have a single positive real root?