![]() | |
![]() |
| | Thread Tools | Display Modes |
#11
| |||
| |||
|
|
j = [ "haha", "again", "last joke"]; Or realize that there are no new jokes. |
#12
| |||
| |||
|
|
"Douglas Crockford" <nospam (AT) laserlink (DOT) net> wrote in message news:bkvlq1$jas$1 (AT) sun-news (DOT) laserlink.net... snip That way, you don't have to number the jokes. Or realize that there are no new jokes. |
#13
| |||
| |||
|
|
j=new Array j[0]="haha" j[1]="next joke" j[2]="again" //.... j[20]="last joke" /script Or you could do Math.random()*3 Or better, use Math.floor(Math.random() * j.length). That way, you don't have to Not in the case under investigation, where there is a gap in the array ! |
#14
| |||
| |||
|
|
Michael wrote on 25 sep 2003 in comp.lang.javascript: "Evertjan." <exjxw.hannivoort (AT) interxnl (DOT) net> wrote in message news:<Xns93FEECF282858eejj99 (AT) 194 (DOT) 109.133.29>... Michael wrote on 22 sep 2003 in comp.lang.javascript: I know how to display random jokes or sayings. But only if I reload the page does the script select a new saying. How can I click on the saying and have it load a new one in its place. script j=new Array j[0]="haha" j[1]="next joke" j[2]="again" //.... j[20]="last joke" /script div onclick="this.innerHTML=j[Math.floor(Math.random()*21)]" Click here for jokes /div This did not quite work. This is just about what I wanted. I keep geting a message that says undefined. I think that the part after innerHTML= has to be in the script too. It works all right, tested on IE6, but you have to fill in all 20 texts, otherwise you get that "undefined" Or you could do Math.random()*3 |
#15
| |||
| |||
|
|
Michael wrote on 25 sep 2003 in comp.lang.javascript: "Evertjan." <exjxw.hannivoort (AT) interxnl (DOT) net> wrote in message news:<Xns93FEECF282858eejj99 (AT) 194 (DOT) 109.133.29>... Michael wrote on 22 sep 2003 in comp.lang.javascript: I know how to display random jokes or sayings. But only if I reload the page does the script select a new saying. How can I click on the saying and have it load a new one in its place. script j=new Array j[0]="haha" j[1]="next joke" j[2]="again" //.... j[20]="last joke" /script div onclick="this.innerHTML=j[Math.floor(Math.random()*21)]" Click here for jokes /div This did not quite work. This is just about what I wanted. I keep geting a message that says undefined. I think that the part after innerHTML= has to be in the script too. It works all right, tested on IE6, but you have to fill in all 20 texts, otherwise you get that "undefined" Or you could do Math.random()*3 |
#16
| |||
| |||
|
|
That script example I last gave you is no good. It just displays the index number, not the joke in the array. For some reason I cannot get it to display the joke. If I put this.innerHTML=j[1] it still says undefined. |
#17
| |||
| |||
|
|
"Mike Painter" <mdotpainter (AT) att (DOT) net> writes: "Douglas Crockford" <nospam (AT) laserlink (DOT) net> wrote in message news:bkvlq1$jas$1 (AT) sun-news (DOT) laserlink.net... snip That way, you don't have to number the jokes. Or realize that there are no new jokes. #751 ? |
![]() |
| Thread Tools | |
| Display Modes | |
| |