It needs to be in a .js file referenced from the page or inlined. See <script> tag documentation on MDN for example.
<script>