javascript - ''x'' is not a function -
the function should return "this true" doesn't appear working. telling me
randomquestion
not defined.
what doing wrong?
//questions function randomquestion() { var quest = "this true"; var string_length = 1; var randomstring = ""; (var i=0; i<string_length; i++) { var rnum = math.floor(math.random() * quest.length); randomquestion += quest.substring(rnum,rnum+1); } document.questions.questfield.value = randomquestion; } <!--questions form--> <form name="questions"> <input type="button" value="question" onclick="randomquestion();"> <input type="text" name="questfield" value=""> </form>
the name of function randomquestion
, in function, write:
randomquestion += ...
i noticed didn't use variable randomstring
in function. maybe want use randomstring +=
instead of using randomquestion += ...
?
here code edited:
<html> <body> <script> function randomquestion() { var quest = "this true"; var string_length = 1; var randomstring = ""; var = 0; var rnum = 0; (i = 0; < string_length; i++) { rnum = math.floor(math.random() * quest.length); randomstring += quest.substring(rnum, rnum + 1); } document.questions.questfield.value = randomstring; } </script> <form name="questions"> <input type="button" value="question" onclick="randomquestion();"> <input type="text" name="questfield" value=""> </form> </body> </html>
Comments
Post a Comment