HTML is not JavaScript.
The <script>
element allows you to embed JavaScript in an HTML document. It is specifically designed for that purpose.
You can’t just dump raw HTML into the middle of a JavaScript function. You can only write JavaScript there. The body of a JavaScript function is not designed to be a place for raw HTML.
MDN has some introductory JavaScript resources which include a guide on manipulating the DOM of an HTML document.