Solution (source code)

= Solution

Taking <determinants> of $M^TJM=J$ gives
$$
\det(M)^2\det J=\det J.
$$
Since $\det J=-1\ne0$, one has $\det(M)^2=1$, and hence
$$
\boxed{\det M=1\quad\text{or}\quad\det M=-1}.
$$
Both values occur, for example for $M=I$ and $M=\operatorname{diag}(1,-1)$.