Hi there, new member, and completely new to javascript. I’m trying to finish this assignment for a class where I need to place random quotes into a webpage using JS and things are just completely wrong and I don’t know how to get it working.
The assignment comes from a book which has me do things in a specific way, so changing the whole script to work differently is out of the question. Can’t change the names of the variables/etc either.
There’s two files for the assignment – random.js , and twain.htm .
random.js
[code]
function randInt (size) {
var rNum = Math.ceil(Math.random()*5);
return rNum;
}
I’m sure that the file is just the mechanism for making the quotes random. I put the number 5 there, because there’s supposed to be 5 quotes in total. Probably wrong to do that.
twain.htm
[code]
<script src=”random.js” type=”text/javascript”></script>
<script type=”text/javascript”>
function getQuote (qNum){
var mtQuotes = new Array ();
mtQuotes[0] = “”;
mtQuotes[1] = “a”;
mtQuotes[2] = “b”;
mtQuotes[3] = “c”;
mtQuotes[4] = “d”;
mtQuotes[5] = “e”;
return mtQuotes;
}
</script>
The part of twain.htm where it should display the random quote:
[code]
<div id=”quotes”>
<script type=”text/javascript”>
var randValue = randInt()+5;
var quoteText = getQuote();
document.write(“[quoteText]”);
</script>
</div>
Well…all I get is [quoteText] showing up in the text box where the quotes should be. From what I’ve seen in the book, the [] should be displaying the variable differently.
So, any way I could get this to work? Any help is greatly appreciated.
Again, I’m completely new to javascript, I’ve only read what I have in my book and that’s all I know about it.