Write a script that uses random number generation to create sentences. Use four arrays of strings called article, noun, verb and preposition. Create a sentence by selecting a word at random from each array in the following order: article, noun, verb, preposition, article and noun. As each word is picked, concatenate it to the previous words in the sentence. The words should be separated by spaces. When the final sentence is output, it should start with a capital letter and end with a period.
The arrays should be filled as follows: the article array should contain the articles "the", "a", "one", "some" and "any"; the noun array should contain the nouns "boy", "girl", "dog", "town" and "car"; the verb array should contain the verbs "drove", "jumped", "ran", "walked" and "skipped"; the preposition array should contain the prepositions "to", "from", "over", "under" and "on".
The program should generate 20 sentences to form a short story and output the result to an XHTML textarea. The story should begin with a line reading "Once upon a time..." and end with a line reading "THE END".

<?xml version = "1.0" encoding = "utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>Sentences</title>
<script type="text/javascript">
<!--
function sentence()
{
var i;
var article= new Array(5);
article[0]="the";
article[1]="a";
article[2]="one";
article[3]="some";
article[4]="any";
var noun= new Array(5);
noun[0]="boy";
noun[1]="girl";
noun[2]="dog";
noun[3]="town";
noun[4]="car";
var verb= new Array(5);
verb[0]="drove";
verb[1]="jumped";
verb[2]="ran";
verb[3]="walked";
verb[4]="skipped";
var preposition= new Array(5);
preposition[0]="to";
preposition[1]="from";
preposition[2]="over";
preposition[3]="under";
preposition[4]="on";
var string1="Once upon a time..." ;
for(i = 0; i < 20; i++)
{
string1 = string1 + caps(article[Math.floor(Math.random()*5)]) + " " + noun[Math.floor(Math.random()*5)] + " " + verb[Math.floor(Math.random()*5)] + " " + preposition[Math.floor(Math.random()*5)] + " " + article[Math.floor(Math.random()*5)] + " " + noun[Math.floor(Math.random()*5)] + "." + "\n";
}
var string2="THE END";
document.writeln(string1 + string2);
}
function caps(a)
{
var first= a.substring(0,1);
var last= a.substring(1);
var output= first.toUpperCase() + last;
return output;
}
// -->
</script>
</head>
<body onload="sentence()">
<table style="width: 100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td valign="top">&nbsp;</td>
<h1>Exercise 11.7 Sentences</h1>
<hr />

<p>Press F5 or Refresh to load script again. This is a program to Output sentences.</p>
</td>
</tr>
</table>

</body>
</html>