using js with less elements

using js with less elements

Hi,
as i seen this page, i wanted to ask for help, today i've wanted to write a "randomize text code without the javascript display in the elements but i couldn't do it can someone tell me what i did wrong and correct me it? also this is an example i want to be same as this.  https://api.rtainc.co/twitch/8ball

and this is my code
  1. <html>
  2. <shadow><script type="text/javascript">
  3. var textarray = [
  4.  "Hi, $(user)",
  5.  "Welcome, $(user)",
  6.  "how r u $(user)",
  7.  "HYD $(user)"
  8. ];

  9. function RndText() {
  10.   var rannum= Math.floor(Math.random()*textarray.length);
  11.   document.getElementById('txt').innerHTML=textarray[rannum];
  12. }
  13. onload = function() { RndText(); }

  14. </script></shadow>

  15. <head></head>
  16. <body>
  17. <pre id="txt" style="word-wrap: break-word; white-space: pre-wrap;"></pre>
  18. </body>
  19. <style></style>
  20. </html>