Below is a Random Quote generator script I found on the net, its a great script, but I want the quote to be in bold, how is that done please?

<center>
<font color="#71025F" size="2" face="Verdana,Arial">
<script language="JavaScript">
// ==============================================

var Quotation=new Array() // do not change this!

// Set up the quotations to be shown, below.
// To add more quotations, continue with the
// pattern, adding to the array.  Remember
// to increment the Quotation[x] index!

Quotation[1] = "Words go here.";
Quotation[2] = "Blar blar, talking.";
Quotation[3] = "Speaking here, talk talk.";

// ======================================
// Do not change anything below this line
// ======================================
var Q = Quotation.length;
var whichQuotation=Math.round(Math.random()*(Q-1));
function showQuotation(){document.write(Quotation[whichQuotation]);}
showQuotation();
</script>

Recommended Answers

All 10 Replies

From the showQuotation() function, replace it with the following format:

function showQuotation() { 
   document.write( "<b>" + Quotation[whichQuotation] + "</b>" );
}

So we do this I am guessing, I will text this out.

<center>
<font color="#71025F" size="2" face="Verdana,Arial">
<script language="JavaScript">
// ==============================================

var Quotation=new Array() // do not change this!

// Set up the quotations to be shown, below.
// To add more quotations, continue with the
// pattern, adding to the array. Remember
// to increment the Quotation[x] index!

Quotation[1] = "Words go here.";
Quotation[2] = "Blar blar, talking.";
Quotation[3] = "Speaking here, talk talk.";

// ======================================
// Do not change anything below this line
// ======================================
var Q = Quotation.length;
var whichQuotation=Math.round(Math.random()*(Q-1));
function showQuotation() { 
   document.write( "<b>" + Quotation[whichQuotation] + "</b>" );
}
</script>

tested it, as written above, makes it not work at all.

I could do with an online javascript tool that one can copy and paste code into so I can quick link when the suggested code does not work.

You forgot to call it:

// after the showQuotation function. -->

function showQuotation() { ... }

[b]showQuotation();[/b] // You'll need to include this line <<<

</script>

Could you show me it with it 'in' the script please, if you would be so kind, as I get confused, I am a 'total newbie' and have to learn from looking at peoples scripts, or it is difficult for me.

Ok wait a sec.

Here is it:

<center>

<font color="#71025F" size="2" face="Verdana,Arial">
<script language="JavaScript">

var Quotation=new Array() 
// do not change this!
// Set up the quotations to be shown, below.
// To add more quotations, continue with the
// pattern, adding to the array. Remember
// to increment theQuotation[x] index!

Quotation[1] = "Words go here.";

Quotation[2] = "Blar blar, talking.";

Quotation[3] = "Speaking here, talk talk.";

// ======================================
// Do not change anything below this line
// ======================================

var Q = Quotation.length;

var whichQuotation = Math.round(Math.random()*(Q-1));

function showQuotation() {

document.write( "<b>" + Quotation[whichQuotation] + "</b>" );
}

showQuotation(); // This is the only line that was added in the entire script.
 

</script>

It works, fantastic :) , thank you so much for your help.

And you are welcome...

This will occasionally produce an "undefined" error because, the way the randomize formula is set up, it may look for array 0. Since you set up arrays starting with 1, you need to alter the formula thus:

var whichQuotation=Math.round(Math.random()*(Q-2)+1);

This way, the minimum number it will generate is 1, which corresponds to the lowest element in the Quotation array.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.