Results 1 to 2 of 2

Thread: operators/prompt

  1. #1

    Thread Starter
    Fanatic Member merhaba's Avatar
    Join Date
    Sep 2002
    Location
    Istanbul,Bartin-Gallipoli(Gelibolu-Canakkale)
    Posts
    601

    operators/prompt

    hi there,
    using prompt I would like to ask the visitors to write any of the"operators"(+,*,- or /)
    and let my script give the correct answer:
    ----------------
    youselected=prompt('write an oprerator','you choose')

    aa=Math.floor(Math.random()*10)
    bb=Math.floor(Math.random()*10)
    cc=(aa..(any operators that my visitors selected.."youselected")......bb)

    could you please help me with this "javascript problem?"

    thanks
    Last edited by merhaba; Oct 24th, 2003 at 06:09 PM.

  2. #2
    Frenzied Member axion_sa's Avatar
    Join Date
    Jan 2002
    Location
    Joburg, RSA
    Posts
    1,724
    var a, b, c;
    var op = prompt("Operator?", "You choose");

    a = Math.floor(Math.random() * 10);
    b = Math.floor(Math.random() * 10);
    eval("c = a " + op + " b;");
    alert(c.toString());

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width