Hey there, I need help with this....must be done in JavaScript Write a script th
ID: 3672653 • 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.
7. There's must be at least 5 arrays somehow!!!! very important!!
Explanation / Answer
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1" />
<meta http-equiv="Content-Language" content="en-us" />
<title>javascript for ga</title>
<script type="javascript">
function win_onload() {
var uarticle= new Array(5)
uarticle[0]="The";
uarticle[1]="A";
uarticle[2]="One";
uarticle[3]="Some";
uarticle[4]="Any";
var larticle= new Array(5)
larticle[0]="the";
larticle[1]="a";
larticle[2]="one";
larticle[3]="some";
larticle[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";
string=""
for(start = 0; start < 20; start++) {
var randomuarticle=Math.floor(Math.random()*5)
var randomnoun=Math.floor(Math.random()*5)
var randomverb=Math.floor(Math.random()*5)
var randompreposition=Math.floor(Math.random()*5)
var randomlarticle=Math.floor(Math.random()*5)
var randomnoun2=Math.floor(Math.random()*5)
string= string+ uarticle[randomuarticle] + " " + noun[randomnoun] +"
" + verb[randomverb] + " " + preposition[randompreposition] + " " +
larticle[randomlarticle] + " " + noun[randomnoun2] + "." +" ";
window.document.form1.text1.value=string
}
}
</script>
</head>
<body>
<form name="form1" action="">
<p><textarea name="text1" rows="25" cols="40" >
</textarea></p>
</form>
</body>
</html>