The simplest JavaScript in the world won't work!

javascript

Solution

I think the src tag overrides whatever's inside.

Try the following:

    <script type="text/javascript" src="JavaScript/Sample.js"></script>
    <script type="text/javascript">
        MyPrint("Hello silly world!");
    </script>

Problem

I have this script in the separate Sample.js file: ``` function MyPrint(text) { document.write(text); } ``` And I have the following HTML page: ``` <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Silly example</title> </head> <body> <div> <script type="text/javascript" src="JavaScript/Sample.js"> MyPrint("Hello silly world!"); </script> </div> </body> </html> ``` Final result is that the text "Hello silly world!" is NOT printed on the page. What should I do to make this work? I would prefer not to move the script tag to the head, if possible. Thanks.

Original source