37 users online (2 members and 35 guests)  


  Results 1 to 4 of 4

Related

  1. Count and rows code    Forum: PHP Forum
    Replies: 0
  2. tracking link clicks    Forum: PHP Forum
    Replies: 15
  3. [How to] More appear & clicks adbrite inline ads    Forum: Affiliate Marketing and Reseller Programs
    Replies: 1
  4. How can count visits?    Forum: PHP Forum
    Replies: 1
  1. #1
    lyssword's Avatar
    New User

    Status
    Offline
    Join Date
    Nov 2005
    Posts
    3

    how to count clicks/guesses?

    at cs101 class we are debugging a little program where the user guesses and the program will tell you if its more/less.

    For extra credit we need to make a message display that when you finally do guess the number correctly, it will display how many times it took you to guess the #.

    I think it supposed to be something like

    count how many times = wrong/not the answer then show that in the final alert box.

    I'm really new at this so I don't even know if its a var or function

  2. #2
    vinyl-junkie's Avatar
    Moderator

    Status
    Offline
    Join Date
    Sep 2005
    Posts
    721

    Re: how to count clicks/guesses?

    Do I get the extra credit if I write your program for you?

    I'm not a javascript programmer, but here's pseudo-code for how your program needs to work.

    Code:
    guess_count = 0
    number_to_guess = *insert some number here*
    repeat
    get the value for current_guess
    if current_guess = number_to_guess
    escape loop
    else
    add 1 to guess_count
    end-if
    end-repeat
    write "number of guesses was: " guess_count
    You have three variables, as follows:

    guess_count = number of guesses it takes to get the correct number

    number_to_guess = self-explanatory

    current_guess = the number you guessed this time
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more

  3. #3
    coothead's Avatar
    bald headed old fart

    Status
    Offline
    Join Date
    Aug 2003
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    732

    Re: how to count clicks/guesses?

    Hi there lyssword, vinyl-junkie,
    here is a working example...
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <title>number guessing</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <style type="text/css">
    <!--
    body {
    color:#000;
    background-color:#eef;
    }
    form {
    margin:20px auto;
    width:360px;
    padding:10px;
    border:3px double #000;
    font-family:verdana,sans-serif;
    font-size:16px;
    color:#000;
    background-color:#ccc;
    }
    input{
    margin:3px 0;
    width:50px;
    text-align:center;
    }
    -->
    </style>
    <script type="text/javascript">
    <!--
    var count;
    var num;
    var  df=document.forms;
    function init() {
    count=0;
    num=Math.floor(Math.random()*100);
    df[0][0].value=count;
    df[0][1].value=count;
    df[0][2].value='';
    }
    function guess() {
    if(isNaN(df[0][0].value)) {
    alert('come on, numbers only!!!');
    df[0][0].value=0;
    return;
    }
    else {
    count++;
    df[0][1].value=count;
    if(count==10) {
    alert('You have failed '+count+' times in your attempt at guessing this number...\n\n'+num);
    return init();
    }
    if(df[0][0].value<num) {
    df[0][2].value='higher';
    }
    else {
    if(df[0][0].value==num) {
    df[0][2].value='';
    alert('congratulations you have correctly guessed the number...\n\n'+num+'\n\n...in '+count+' guesses')
    }
    else {
    df[0][2].value='lower';
    }
    }
    }
    }
    onload=init;
    //-->
    </script>
    </head>
    <body>
    <form action="#">
    <div>
    <input class="text" type="text"><label> : enter a guess between 0 and 99</label>
    <input class="text" type="text" readonly="readonly"><label> : number of guesses -allowed 10</label>
    <input class="text" type="text" readonly="readonly"><label> : higher or lower</label>
    </div>
    <div>
    <input type="button" value="guess" onclick="guess()">
    <input type="button" value="clear" onclick="init()">
    </div>
    </form>
    </body>
    </html>

  4. #4
    lyssword's Avatar
    New User

    Status
    Offline
    Join Date
    Nov 2005
    Posts
    3

    Re: how to count clicks/guesses?

    heh thx for the help guys, but I had figured it out pretty easy and got the extra credit. the trick was to do ++ after each function and then display the totals when guessed correctly



Tags for this Thread