Display text string with Javascript on screen

How to display text string with Javascript on screen?

This is my test page:

<html>
test
<script type="text/javascript">
	  docwrite(1);
          document.write('hi');
	  docwrite('hello');
</script>
docwrite(2);

<script type="text/javascript">
function docwrite(x)
{
  document.write(x);
}
</script>
</html>

I saw only “test docwrite(2);”.
I want to see “test 1 hi hello docwrite(2);” with " 1 hi hello" coming from Javascript.
How to do that?

When the web browser gets to a script, you need to realise that for the web browser, nothing else after the script exists.

The docwrite function needs to be moved up before the script the uses it.

Thanks.

Make sure the docwrite(2); is inside script tags or it won’t be interpreted as JavaScript.