Induced map on Eilenberg-MacLane space Let $X$ be an $n-1$ connected space. Why does a map $X\rightarrow K(\pi_n(X),n)$ that induces an isomorphism on $\pi_n$ exist and what is this map?

As stated, the statement is false.  For example, let $X$ be the Hawaiian earring.  Then $X$ is 0-connected.  But $X$ can't have a map to an Eilenberg-Maclane space that's an isomorphism on $\pi_1$, because as a compact space it would have to have compact image, which would necessarily have finitely-generated $\pi_1$ in a CW complex like an Eilenberg-Maclane space, and $X$ has infinitely generated fundamental group.  The statement is true for if $X$ is a CW-complex, as wckronholm explains.
