|
|
Subject:
javascript beginners homework
Category: Computers > Programming Asked by: hydro71-ga List Price: $10.00 |
Posted:
18 Oct 2003 13:00 PDT
Expires: 17 Nov 2003 12:00 PST Question ID: 267498 |
Write a script thta 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, noun. As each word is picked, concatenate it to the previous words in teh 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 program should generate 20 sentences and output them to xhtml textarea. Teh arrays should be filled as follows: the article array shoudl 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. |
|
Subject:
Re: javascript beginners homework
Answered By: andyt-ga on 20 Oct 2003 20:26 PDT |
Hi hydro71-ga, Here is the code that does what you ask, it validates as XHTML transitional 1.0, as requested. If you require any clarification, please don't hesitate to ask. Most of this was done without research, but a trememndous resouce for javascript is located at the internet related technologies page for javascript. They have articles http://tech.irt.org/articles/script.htm and an extensive FAQ (http://developer.irt.org/script/script.htm). Regards, andyt-ga HTML Attachment--------------------- <!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] + "." +"\n"; window.document.form1.text1.value=string } } </script> </head> <body onload="win_onload()"> <form name="form1" action=""> <p><textarea name="text1" rows="25" cols="40" > </textarea></p> </form> </body> </html> | |
| |
| |
| |
|
|
There are no comments at this time. |
If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you. |
Search Google Answers for |
Google Home - Answers FAQ - Terms of Service - Privacy Policy |