Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-10-2012, 08:53 PM   PM User | #1
Xaizhun
New to the CF scene

 
Join Date: Feb 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Xaizhun is an unknown quantity at this point
Question Random Array help

Hi, I'm pretty new to JS and have been trying to get a random array code to work. I have looked over my script multiple times and cannot seem to find what's wrong with the script. I'm hoping someone more experience can help me find what I'm doing wrong. Thanks

Code:
<html>
<HEAD>
 <SCRIPT language="JavaScript">
<!--
function get_random()
{
    var ranNum= Math.floor(Math.random()*8);
    return ranNum;
}

function getaQuote()
{
   var whichQuote=get_random();

    var quote=new Array(8)
     quote[0]="An expletive used by knowledgeable film buffs during any chase scene involving a foreign or ethnic locale, reflecting their certainty that a fruit cart will be overturned during the chase, and an angry peddler will run into the middle of the street to shake his fist at the hero\'s departing vehicle.";
	quote[1]="In any horror film involving a human transforming into a monster, the hero never has to explain to the police the naked dead human body that is left after he has killed the monster. This despite the fact that no one in authority ever believes in the monster in the first place.";
	quote[2]="Any stolen clothing or shoes will perfectly fit any male character whether they were stolen from a clothesline or removed from a Nazi guard, police officer, lookout, etc., who was overpowered and whose identity the clothing thief has now assumed";
	quote[3]="In horror films that feature a mad scientist there is always a scene where the scientist explains the rational for his bizarre experiments. After the explanation, the scientist will always turn to his guest and say, 'You think I\'m mad, don\'t you?'”;
	quote[4]="If there is more than one or two of an alien race, they are always roughly the same size as humans.";
	quote[5]="Aliens usually speak english and have same colloquialisms. planet";
	quote[6]="All members of alien species wear the same outfits, including clothing, hairstyles, and jewelery. This makes them readily identifiable. Aliens who do not dress like aliens are hiding something.";
	quote[7]="This may, in fact, be a consequence of the fact that aliens all have single, monolithic cultures: one language, one religion, one outfit, per planet.";
  
   alert(quote[whichQuote]);
  }
//-->
</SCRIPT>
</HEAD>

<BODY>
<FORM name="form1">
<INPUT TYPE="button" value="Get a Quote!" onClick="getaQuote()">
</FORM>   
</BODY>
</html>
Xaizhun is offline   Reply With Quote
Old 02-10-2012, 09:16 PM   PM User | #2
venegal
Gütkodierer


 
Join Date: Apr 2009
Posts: 2,127
Thanks: 1
Thanked 426 Times in 424 Posts
venegal has a spectacular aura aboutvenegal has a spectacular aura about
You're obviously learning from an outdated source, which isn't great, but what's really tripping your script up is the fact that for quote[3] you're using instead of " as closing quote.
__________________
.My new Javascript tutorial site: http://reallifejs.com/
.Latest article: Calculators — Tiny jQuery calculator, Full-fledged OOP calculator, Big number calculator
.Latest quick-bit: Including jQuery — Environment-aware minification and CDNs with local fallback
venegal is offline   Reply With Quote
Old 02-11-2012, 12:06 AM   PM User | #3
Xaizhun
New to the CF scene

 
Join Date: Feb 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Xaizhun is an unknown quantity at this point
Thanks! I don't know how many times I went over my code looking for small mistakes like that. Just needed another pair of eyes I guess. Thanks so much, maybe I can find an updated way of doing it now that I know what was going wrong.
Xaizhun is offline   Reply With Quote
Reply

Bookmarks

Tags
array, javascript, random

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:06 AM.


Advertisement
Log in to turn off these ads.