Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hey there, I need help with this....must be done in JavaScript Write a script th

ID: 3671995 • Letter: H

Question

Hey there, I need help with this....must be done in JavaScript

Write a script that uses random number generation to create sentences. Use FIVE 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".

ALSO must include these changes...

1.Capitalize the first letter of each sentence, of course.

2.The logic of the resulting story can't be helped, but the spacing can.
Here's an example:
"The car ran to the town.Some boy jumped over a car." Correct for it.

3. Keep track of how many times each word is used.

4.The first time a noun is used in the story, it must take
the article "a".

5.After a noun has been used, it can no longer use "a".
Check my logic here: this requirement means

the first sentence will contain two "a"s (most times), and

we'll only see the word "a" five times (or fewer).

6. At the end of the page, display an alphabetized list of the words
available for the story, along with the number of times each was used.

Explanation / Answer

<script language="JAVASCRIPT" type="TEXT/JAVASCRIPT">
function generate()
{
A=new Array("the","a","one","some","any");
N=new Array("boy","girl","dog","town","ear");
V=new Array("drove","jumped","ran","walked","skipped");
P=new Array("to","from","over","under","on");
sent="";
total="";
for(i=0;i<20;i++)
{
w1=new String(A[Math.round(Math.random()*4)]);
w2=new String(N[Math.round(Math.random()*4)]);
w3=new String(V[Math.round(Math.random()*4)]);
w4=new String(P[Math.round(Math.random()*4)]);
w5=new String(A[Math.round(Math.random()*4)]);
w6=new String(N[Math.round(Math.random()*4)]);

s1=w1.substr(0,1);
s2=w1.substr(1,3);
w1=s1.toUpperCase()+s2;
sent=w1+" "+w2+" "+w3+" "+w4+" "+w5+" "+w6+"."+" ";
total=total+sent;
}
document.f1.t1.value=total;
}
</script>
<form name="f1">
<h1> Sentences</h1><br />
<textarea rows=20 cols=50 name="t1">