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? Commented Feb 20, 2012 at 22:33
  • ah, sorry. when I run it, it displays nothing in the browser where I'm calling the function. Commented 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 Commented Feb 20, 2012 at 22:35
  • 1
    lack of r-? sorry, I'm a bit confused. Commented Feb 20, 2012 at 22:39
  • +1 for valiant but vain attempt to fix by adding mysterious "r". Commented 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.

Sign up to request clarification or add additional context in comments.

1 Comment

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?
1

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

Comments

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 Comment

Ah, yes, exactly. Thank you very much. I will check out SciTe, instead of eclipse. Cheerio!
0

You are missing the ending ] in the return command.

1 Comment

Thanks! This was the big problem, among other things.
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.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.