0

I've been fiddling with this HTML and javascript for an hour or two now...and I can't figure out why it's not working. I've been trying to learn html, css, and javascript on my own...but I don't think Eclipse is debugging my stuff very well...what's going on?

<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<style type="text/css">
a:link {color:#FF0000;}    /* unvisited link */
a:visited {color:#00FF00;} /* visited link */
a:hover {color:#FF00FF;}   /* mouse over link */
a:active {color:#0000FF;}  /* selected link */
</style>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Catlard.com</title>

<link rel=StyleSheet href="styles/menuStyle.css" type="text/css"/>

<script type="text/javascript">

function RandomQuote()
{
    var quotes= new Array();
    quotes[0] = "...believes it may be useful in a time of need."
    quotes[1] = "...knows you have a problem, but accepts you anyway."
    quotes[2] = "...believes the aliens were involved at Oak Island."
    quotes[3] = "...demands to know the location of your hidden rebel base!"
    quotes[4] = "...SAW you take the cookie from the cookie jar."
    return quotes[Math.floor(Math.random() * 4.99);
}

</script>

</head>
<body>

<div id="framecontent">
<div class="innertube">
<h1>CSS Top Frame Layout</h1>
<span style="font-family : Courier;color: #000000;">
<a href="resume.html"> Resume </a>
<a href="http://catlard.blogspot.com"> Blog </a>
<a href="pixelating.html"> Arts n' Farts</a>
<a href="contact.html"> Contact </a>
<a href="typing.html"> Games </a>
</span>
</div>
</div>


<div id="maincontent">
<div class="innertube">

document.write(RandomQuote());
<p style="text-align: center">Blah blah blah </p>
</div>
</div>

</body>
</html>
6
  • You're not telling us what happens when you run this. What is the problem?
    – Beska
    Feb 20, 2012 at 22:33
  • ah, sorry. when I run it, it displays nothing in the browser where I'm calling the function.
    – Catlard
    Feb 20, 2012 at 22:35
  • Because you do not call your code. It's formatted as text. Try putting it into another script tag. -1 for lack of r Feb 20, 2012 at 22:35
  • 1
    lack of r-? sorry, I'm a bit confused.
    – Catlard
    Feb 20, 2012 at 22:39
  • +1 for valiant but vain attempt to fix by adding mysterious "r".
    – Beska
    Feb 20, 2012 at 22:41

5 Answers 5

1

You have an error on the return quotes line. It should close with )]; not );

Also, each of your quotes[n] lines should end with a semicolon.

And, you should have document.write() inside of script tags.

1
  • Ah, this is exactly correct. I did all these things, and now it's working. I apologize for all my syntax errors--I don't have a very good IDE--I'm using Eclipse for Javascript at the moment. Any suggestions for a beginner on OSX 32 bit?
    – Catlard
    Feb 20, 2012 at 22:42
1

Your "document.write" line needs to be in a <script> area. You are also missing the "]" bracket on your return line.

0
0

You need to check your code a bit more clearly. Perhaps use a syntax highlighting programming editor such as SciTe.

Even though you did not explicity tell us the problem you have (just said its not working) the first thing that jumps out at me is this line:

return quotes[Math.floor(Math.random() * 4.99);

You forgot the ending ] on the array.

1
  • Ah, yes, exactly. Thank you very much. I will check out SciTe, instead of eclipse. Cheerio!
    – Catlard
    Feb 20, 2012 at 22:42
0

You are missing the ending ] in the return command.

1
  • Thanks! This was the big problem, among other things.
    – Catlard
    Feb 20, 2012 at 22:43
0

2 things:

return quotes[Math.floor(Math.random() * 4.99)];

You're missing the closing tag for your quotes array.

<script language="javascript" type="text/javascript">
    document.write(RandomQuote());
</script>

Your javascript has to be wrapped in that script tag, or else it's just rendered as HTML.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.