/    Sign up×
Community /Pin to ProfileBookmark

large array with vocab words

can anyone help me diagnose this file? nothing is outputted.

<html>
<head>
</head>
<script type=”text/javascript”>
<!–
var r_text = new Array ();
r_text[0]=”nusnu”;
r_text[1]=”bhbtrh”;
.
.
.
.
r_text[5000]=”hsm7i”;
phraseCnt = r_text.length;
var i = Math.floor(phraseCnt*Math.random())
document.write(r_text[i]);
//–>
</script>

</html>

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@Declan1991Aug 10.2010 — document.write(i);That should show you why it isn't working, and the solution is to use this instead.document.write(r_text[[B]Math.floor([/B]r_text.length*Math.random()[B])[/B]]);

EDIT: I totally missed the Math.floor() when I read that the first time. It works fine for me like that, provided that you have all the values filled in.

As a side note, it would be easier for you to declare your array using JSON.var r_text = ["no. 1", "no. 2", "no. 3" /* etc. */];
Copy linkTweet thisAlerts:
@Sterling_IsfineAug 10.2010 — Provided that there are no gaps in the subscripting, I don't see anything wrong and it does run.

Did you really write [FONT="Courier New"][COLOR="Blue"]r_text[n]= 'word' [/COLOR][/FONT] 5000 times?
Copy linkTweet thisAlerts:
@rty1138authorAug 10.2010 — i actually have vocab words in there. so it's a long string, not just one word.
Copy linkTweet thisAlerts:
@rty1138authorAug 10.2010 — fixed. i had a stray quotation mark at the 319th array.
×

Success!

Help @rty1138 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.5,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...