To put the JavaScript code in an external file, follow these steps:
1. Create a new file with a .js extension (e.g., script.js).
2. Open the script.js file in a text editor.
3. Copy and paste the JavaScript code from the <script> tags in your HTML file into the script.js file.
4. Save the script.js file.
5. In your HTML file, replace the JavaScript code inside the <script> tags with a link to the external JavaScript file.
You can do this by adding the following line in the <head> section:
```html
<script src="script.js"></script>
```
Here's how the updated code would look like:
```html
<html>
<head>
<script src="script.js"></script>
</head>
<body onload="test()">
</body>
</html>
```
Now the JavaScript code is in a separate file, script.js, and linked to the HTML file.