/    Sign up×
Community /Pin to ProfileBookmark

help with changing font in random text script

Hello, im very new to javascript (hours new) and found this code at Javascript Source. It indeed does what it’s supposed to do, wich is displaying different text every time the site is loaded. That’s fine, but I want to change the random text font to Arial and the font size too. I’ve tried to do it with font tags as in a write.document but it doesnt work and as Im a complete noob in the scripting stuff, I have absolutely no idea why, tough I assume it’s because this oje displays random stuff. Could anyone PLEASE help? Im lost here and I really want to know why.

this is the code:

<CENTER>
<SCRIPT LANGUAGE=”Javascript”><!–

function text() {
};

text = new text();
number = 0;

// textArray
text[number++] = “Random text string 1.”
text[number++] = “Random text string 2.”
text[number++] = “Random text string 3.”
text[number++] = “Random text string 4.”
text[number++] = “Random text string 5.”
// keep adding items here…

increment = Math.floor(Math.random() * number);

document.write(text[increment]);

//–></CENTER></SCRIPT>

thanks in advance (:

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@CharlesOct 03.2005 — The CENTER andFONT elementswere removed from HTML back in the last century. &lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd"&gt;
&lt;html lang="en"&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"&gt;
&lt;meta name="Content-Script-Type" content="text/javascript"&gt;
&lt;meta name="Content-Style-Type" content="text/css"&gt;
&lt;title&gt;Example&lt;/title&gt;

&lt;script type="text/javascript"&gt;

Array.prototype.random = function () {return this[Math.floor(Math.random() * this.length)]}

text = ['ETAOIN', 'SHRDLU', 'CMFGYP', 'WBVKXJ', 'QZ']
family = ['Ariel', 'Georgia', 'Symbol']
size = ['10pt', '11pt', '12pt', '13pt']
align = ['left', 'center', 'right']

if (document.getElementsByTagName) onload = function () {
var body = document.getElementsByTagName ('BODY')[0]
var p = document.createElement ('P')
var t = document.createTextNode (text.random())

<i> </i>p.style.fontFamily = family.random()
<i> </i>p.style.fontSize = size.random()
<i> </i>p.style.textAlign = align.random()

<i> </i>p.appendChild(t)
<i> </i>body.appendChild (p)
}

&lt;/script&gt;

&lt;/head&gt;
&lt;body&gt;

&lt;/body&gt;
&lt;/html&gt;
×

Success!

Help @Cano spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...