Closed Thread Icon

Topic awaiting preservation: My first Javascript..And Question Pages that link to <a href="https://ozoneasylum.com/backlink?for=8462" title="Pages that link to Topic awaiting preservation: My first Javascript..And Question" rel="nofollow" >Topic awaiting preservation: My first Javascript..And Question\

 
Author Thread
wilmonkey
Paranoid (IV) Inmate

From: The Jungle
Insane since: Jul 2001

posted posted 01-14-2003 20:40

Ok, after a few months of designing nothing, I decided to dive right into learning Javascript. I went to W3schools.com and took the crash course there on JS and wrote a script to print a random word/picture each time the pages loads. (Seen below) My question is, Could I have done this coding a different way with the same results? (ie shorter script, different commands...etc) I've very new to coding, so any help you gurus can give would be great.

quote:
<script type="text/javascript">
var n=Math.random()*10
switch (Math.floor(n))
{
case 0:
document.write("cow")
break
case 1:
document.write("baby")
break
case 2:
document.write("wheat")
break
case 3:
document.write("grass")
break
case 4:
document.write("mop")
break
case 5:
document.write("mook")
break
case 6:
document.write("bull")
break
case 7:
document.write("cat")
break
case 8:
document.write("dog")
break
case 9:
document.write("dust")
}
</script>



-Wil



[This message has been edited by wilmonkey (edited 01-14-2003).]

InI
Paranoid (IV) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 01-14-2003 21:02

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

Emperor
Maniac (V) Mad Scientist with Finglongers

From: Cell 53, East Wing
Insane since: Jul 2001

posted posted 01-14-2003 21:08

wilmonkey: I would put all the words into an array and then pull them out like myArray[n].

[edit: Dammit InI is too quick for me again I would have sneked in first but loads of really important stuff happened and urmmmm the dog stole the mouse and.....]

___________________
Emps

FAQs: Emperor

wilmonkey
Paranoid (IV) Inmate

From: The Jungle
Insane since: Jul 2001

posted posted 01-14-2003 21:58

Great , Thanks InI and Emps (even though you were late :P )

Now that I can get into gurusnetwork again I will check out the tuts there as well.

-Wil

« BackwardsOnwards »

Show Forum Drop Down Menu