MarvinTheRobot
02-10-2003, 04:29 PM
Hi I am MarvinTheRobot (Hitchhikers guide fan :D) I will be 16 (on feb 17), and I am in 10th grade
I am doing this as a project for my school on my free time (not H/W and no grade will be given)
It is for a writing 10 class. The Objective is to get a few weighted random genres to show up when the student clicks on it. I have compiled the basic script, but seeing as I am a JS newb, It has several problems. (due to bad codeing)
I have kept it to 4 genres for now, and the script "should" addapt to any new genres added.
The first problem is that the generator code always produces an error. It has nothing to do with the forms
The second problem is with the forms, The first button stays depressed, and nothing happens. I am not shure if java is ment to do this, and I am shure there is a better (working :))way of doing it.
If you can tell me why these things don't work, it would help alot.
Here is the basic script:
<script>
function random_genre(){
var genres=["dbq", "essay", "humor", "poem"]
var genreweight=[2, 4, 1, 3]
var totalweight=eval(genreweight.join("+"))
var weighedgenres=new Array()
var currentgenre=0
while (currentgenre<genres.langth){
for (i=0; i<genreweight[currentgenre]; i++)
weighedgenres[weighedgenres.length]=genres[currentgenre]
currentgenre++}
var randomnumber=Math.floor(Math.random()*totalweight)
document.write('<form id=form1 name=form1><input type="button" name="b2" value="Click Here To See It!" onclick=document.write(weighedgenres[randomnumber]')}
</script>
I am doing this as a project for my school on my free time (not H/W and no grade will be given)
It is for a writing 10 class. The Objective is to get a few weighted random genres to show up when the student clicks on it. I have compiled the basic script, but seeing as I am a JS newb, It has several problems. (due to bad codeing)
I have kept it to 4 genres for now, and the script "should" addapt to any new genres added.
The first problem is that the generator code always produces an error. It has nothing to do with the forms
The second problem is with the forms, The first button stays depressed, and nothing happens. I am not shure if java is ment to do this, and I am shure there is a better (working :))way of doing it.
If you can tell me why these things don't work, it would help alot.
Here is the basic script:
<script>
function random_genre(){
var genres=["dbq", "essay", "humor", "poem"]
var genreweight=[2, 4, 1, 3]
var totalweight=eval(genreweight.join("+"))
var weighedgenres=new Array()
var currentgenre=0
while (currentgenre<genres.langth){
for (i=0; i<genreweight[currentgenre]; i++)
weighedgenres[weighedgenres.length]=genres[currentgenre]
currentgenre++}
var randomnumber=Math.floor(Math.random()*totalweight)
document.write('<form id=form1 name=form1><input type="button" name="b2" value="Click Here To See It!" onclick=document.write(weighedgenres[randomnumber]')}
</script>