Posted By

michellebracken on 12/25/10


Tagged


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

michellebracken


"Magic Eight Ball"


 / Published in: HTML
 

Under var answers = new Array(, all possible answers must be inside quotes, then have a comma after the closing quote. You may add/remove/change any of the possibilities.

  1. <SCRIPT LANGUAGE="JavaScript">
  2. <!-- Begin
  3. var answers = new Array(
  4. "Yes.",
  5. "No.",
  6. "My sources are pointing toward yes.",
  7. "It's possible.",
  8. "Very unlikely.",
  9. "Can you repeat the question?",
  10. "Absolutely not.",
  11. "Sure.",
  12. "Ask again later."
  13. );
  14. function fortune() {
  15. num = Math.round( (answers.length - 1) * Math.random());
  16. return answers[num];
  17. }
  18. // End -->
  19.  
  20.  
  21.  
  22. <b>Your question:</b><br>
  23. <input type=text name=question size=35>
  24.  
  25. <input type=button name=ask value="ask" onClick="if (this.form.question.value!='') this.form.answer.value = fortune();"><b>Answer:</b><br>
  26. <input type=text name=answer size=35>
  27. </form>

Report this snippet  

You need to login to post a comment.