English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I have a kind of particular problem which is I don't know how to use Javascript although I must create a simple page in a short period of time.

Anyway the thing is I have to create a "next" button or something and when I click on it, the page will randomly show a word among all the others, say, "Anywhere", "Nowhere", "Everywhere". Sure,I'm going to insert new words into the html document,however I don't want to see the same word before other words do not appear on the page. I mean for example "Anywhere" will not appear if both "Nowhere" and "Everywhere" have not appeared yet. If the other two words have appeared, then "Anywhere" can be seen again. The same rule applies for each word.

Could someone please write some code fragments for this specific problem ? and I want to know where to insert the entire code.. Thanx!

2007-12-06 02:05:48 · 2 answers · asked by nothing_imp7 1 in Computers & Internet Programming & Design

2 answers









type="button"
value="click to insert a word"
onclick="insertWord();" />






2007-12-06 03:44:43 · answer #1 · answered by richarduie 6 · 1 0

I used (1) a subroutine I wrote to generate a random integer between two input integers, inclusive:
/* random positive integer: default range is 0 to 999 */;
function rnd(lo,hi) { var i=0;
isNaN(lo)?lo=0:lo=Math.floor(lo); isNaN(hi)?hi=999:hi=Math.floor(hi);
if (lo<0) lo=Math.abs(lo); if (hi<0) hi=Math.abs(hi);
if (lo>hi) { i=lo; lo=hi; hi=i; }
if (lo==hi) { if (lo==0) hi=999; else lo=0; }
return Math.round(Math.random()*(hi-lo))+lo; }
...and then in your html something like...

This is where
is where the word is.

2007-12-06 10:21:27 · answer #2 · answered by fjpoblam 7 · 0 1

fedest.com, questions and answers