Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Sep 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Sum of same variables in a repeated function

    <!DOCTYPE html>
    <html>
    <body>
    <button onclick="myFunction3()">Click here to start le quiz</button>
    <p id="q"></p>
    <script>
    function myFunction3()
    {
    var x=Math.floor((Math.random()*12)+1);
    var y=Math.floor((Math.random()*12)+1);
    var score;
    var attempt;
    var Tattempt=sum(attempt)

    if (Tattempt<11)
    {
    prompt(x + "x" + y + "=?","");
    var name=prompt(x + "x" + y + "=?","");
    if (name=x*y)
    {
    score=1;
    attempt=1;
    }
    else if (name!=x*y)
    {
    score=0;
    attempt=1;
    }
    else
    {
    var z="You've got" + sum(score) + "Out of 10!";
    document.getElementById("q").innerHTML=z
    }
    }
    }
    </script>
    </body>
    </html>

    ____________________________________________________________
    1. Please state any errors in this code. (If any)
    2. I want to create a math quiz on multiplication using JavaScript. Questions are to be randomly generated and separately displayed in a prompt box. The user must recieve a score out of ten. A prompt box for the result is optional.
    Last edited by qwertyoone; 09-23-2012 at 09:24 AM.

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,730
    Thanks
    202
    Thanked 2,507 Times in 2,485 Posts
    Quote Originally Posted by qwertyoone View Post
    1. Please state any errors in this code. (If any)
    2. I want to create a math quiz on multiplication using JavaScript. Questions are to be randomly generated and separately displayed in a prompt box. The user must recieve a score out of ten. A prompt box for the result is optional.
    1. Have you tried using yuur error console? What error messages do you receive? There is no function sum in Javascript.

    2. This forum is not a free coding service. As a general rule, the people helping out in this forum don't write code for others, but try to help with fixing code that doesn't work. You may perhaps get someone to write this script for you, but you'll be far more likely to get help if you have made a substantial effort and written some code yourself. Then someone here will almost certainly help you correct/improve your work.


    "To get back my youth I would do anything in the world, except take exercise, get up early, or be respectable."- Oscar Wilde (Irish Poet, Novelist, Dramatist and Critic, 1854-1900)

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.


  •  

    Tags for this Thread

    Posting Permissions

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