How can I create the environment that could count words inside itself? More specifically, I want to write an enviroment called "assignment" such that the code
\begin{assignment}
Some words here.
\end{assignment}
will result in "Some words here." in the text and, say, "3 words" in a margin paragraph.
I tried searching for that, but found only (external) tools to count words in the entire document, while I need to do this with LaTeX code and for a single environment (possibly repeated several times in a document).