Petoux
28th November 2006, 05:30 PM
First...I will give the code, and then I will state the problem I am trying to fix and find.
In this website, I have two other files embedded in my sight.
This first one is a regular text file which is an external source of the javascript:
function randInt(size){
var rNum = Math.ceil(Math.random()*1);
return rNum;
}
This next one is a css file that is an external source of a few added things, not sure if it relates to javascript, but here is the code anyway:
body {background-image: url(paper.gif); color: black}
#leftcol {float: left; margin-right: 10px; width: 220px}
#main {float: left; width: 400px; padding: 5px}
#quotes {text-align: center; background-color: white; color: black;
border: 3px outset white; font-family: sans-serif; padding: 2px;
font-size: 10pt}
li {list-style-image: url(button.gif); padding-left: 5px}
li a {font-size: 8pt; font-family: sans-serif}
The final part is my website HTML code, which is the main one I have been having troubles with the javascript, and I think I have an idea how to fix it, but I'm not sure how to do it.
Here is the code...everything bolded is what I am having trouble with, and then they are referenced seperately below:
<title>The Mark Twain Quotes Page</title>
<link href="mtstyles.css" rel="stylesheet" type="text/css" />
<script src="random.js.js" type="text/javascript" />
<script type="text/javascript">
function getQuote(qNum){
var mtQuotes=new Array(5);
mtQuotes[1]="I smoke in moderation, only one cigar at a time.";
mtQuotes[2]="Be careful of reading health books, you might die of a misprint.";
mtQuotes[3]="Man is the only animal that blushes or needs to.";
mtQuotes[4]="Clothes make the man. Naked people have little or no influence on society.";
mtQuotes[5]="One of the most striking differences between a cat and a lie is that a cat has only nine lives.";
return mtQuotes[qNum];
}
</script>
</head>
<body>
<div id="leftcol">
<img src="twain.gif" alt="Mark Twain" />
<br />
<div id="quotes">
<script type="text/javascript">
function{
var randValue = Math.ceil(Math.random()*5);
var quoteText = getQuote(qNum);
return();
/* document.write("quoteText"); */
}
</script>
</div>
etc...
Refered singularly:
<script src="random.js.js" type="text/javascript" />
The above statement has a basic syntax of <script type="mime-type">script commands and comments</script>
But is it random.js or random.js.js?
Also, this is an external file and the syntax looks right to me.
...
<script type="text/javascript">
function getQuote(qNum){
var mtQuotes=new Array(5);
mtQuotes[1]="I smoke in moderation, only one cigar at a time.";
mtQuotes[2]="Be careful of reading health books, you might die of a misprint.";
mtQuotes[3]="Man is the only animal that blushes or needs to.";
mtQuotes[4]="Clothes make the man. Naked people have little or no influence on society.";
mtQuotes[5]="One of the most striking differences between a cat and a lie is that a cat has only nine lives.";
return mtQuotes[qNum];
}
</script>
This function is supposed to create an array named mtQuotes that contains five quotes each with an assigned index which I have just fine...it seems.
It is supposed to return the value of mtQuotes array for ghe qNum index.
The syntax looks correct, so I'm not sure what's wrong.
...
<script type="text/javascript">
function{
var randValue = Math.ceil(Math.random()*5);
var quoteText = getQuote(qNum);
return();
/* document.write("quoteText"); */
}
</script>
This script is also an embedded type, and it has the right <script></script> code.
The problem with this one is that the function doesn't have a name, and I'm not sure what to name it.
The function is supposed to declare a variable called "randValue" which is supposed to pick a random integer between 1 and 5 with rounding up the number. That is done, so I don't think anything is wrong with that one.
Yet here is the main problem I am trying to solve:
I want to decare a variable named "quoteText" {Which I have} which contains the Mark Twain quote whose array index value is equal to randValue.
I'm not sure how to do that, but my best quess is somehow use the getQuote() function I created to extract the correct quote from the array. Yet I'm not sure how to do it.
Can you help me? Is my syntax wrong? Is their sometimg I'm missing? Anything?
Thanks...
:D
In this website, I have two other files embedded in my sight.
This first one is a regular text file which is an external source of the javascript:
function randInt(size){
var rNum = Math.ceil(Math.random()*1);
return rNum;
}
This next one is a css file that is an external source of a few added things, not sure if it relates to javascript, but here is the code anyway:
body {background-image: url(paper.gif); color: black}
#leftcol {float: left; margin-right: 10px; width: 220px}
#main {float: left; width: 400px; padding: 5px}
#quotes {text-align: center; background-color: white; color: black;
border: 3px outset white; font-family: sans-serif; padding: 2px;
font-size: 10pt}
li {list-style-image: url(button.gif); padding-left: 5px}
li a {font-size: 8pt; font-family: sans-serif}
The final part is my website HTML code, which is the main one I have been having troubles with the javascript, and I think I have an idea how to fix it, but I'm not sure how to do it.
Here is the code...everything bolded is what I am having trouble with, and then they are referenced seperately below:
<title>The Mark Twain Quotes Page</title>
<link href="mtstyles.css" rel="stylesheet" type="text/css" />
<script src="random.js.js" type="text/javascript" />
<script type="text/javascript">
function getQuote(qNum){
var mtQuotes=new Array(5);
mtQuotes[1]="I smoke in moderation, only one cigar at a time.";
mtQuotes[2]="Be careful of reading health books, you might die of a misprint.";
mtQuotes[3]="Man is the only animal that blushes or needs to.";
mtQuotes[4]="Clothes make the man. Naked people have little or no influence on society.";
mtQuotes[5]="One of the most striking differences between a cat and a lie is that a cat has only nine lives.";
return mtQuotes[qNum];
}
</script>
</head>
<body>
<div id="leftcol">
<img src="twain.gif" alt="Mark Twain" />
<br />
<div id="quotes">
<script type="text/javascript">
function{
var randValue = Math.ceil(Math.random()*5);
var quoteText = getQuote(qNum);
return();
/* document.write("quoteText"); */
}
</script>
</div>
etc...
Refered singularly:
<script src="random.js.js" type="text/javascript" />
The above statement has a basic syntax of <script type="mime-type">script commands and comments</script>
But is it random.js or random.js.js?
Also, this is an external file and the syntax looks right to me.
...
<script type="text/javascript">
function getQuote(qNum){
var mtQuotes=new Array(5);
mtQuotes[1]="I smoke in moderation, only one cigar at a time.";
mtQuotes[2]="Be careful of reading health books, you might die of a misprint.";
mtQuotes[3]="Man is the only animal that blushes or needs to.";
mtQuotes[4]="Clothes make the man. Naked people have little or no influence on society.";
mtQuotes[5]="One of the most striking differences between a cat and a lie is that a cat has only nine lives.";
return mtQuotes[qNum];
}
</script>
This function is supposed to create an array named mtQuotes that contains five quotes each with an assigned index which I have just fine...it seems.
It is supposed to return the value of mtQuotes array for ghe qNum index.
The syntax looks correct, so I'm not sure what's wrong.
...
<script type="text/javascript">
function{
var randValue = Math.ceil(Math.random()*5);
var quoteText = getQuote(qNum);
return();
/* document.write("quoteText"); */
}
</script>
This script is also an embedded type, and it has the right <script></script> code.
The problem with this one is that the function doesn't have a name, and I'm not sure what to name it.
The function is supposed to declare a variable called "randValue" which is supposed to pick a random integer between 1 and 5 with rounding up the number. That is done, so I don't think anything is wrong with that one.
Yet here is the main problem I am trying to solve:
I want to decare a variable named "quoteText" {Which I have} which contains the Mark Twain quote whose array index value is equal to randValue.
I'm not sure how to do that, but my best quess is somehow use the getQuote() function I created to extract the correct quote from the array. Yet I'm not sure how to do it.
Can you help me? Is my syntax wrong? Is their sometimg I'm missing? Anything?
Thanks...
:D