Web Analytics Made Easy -
StatCounter prompt dialogue box help please - CodingForum

Announcement

Collapse
No announcement yet.

prompt dialogue box help please

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • prompt dialogue box help please

    Anyone please help.

    I am trying to build a game in Javascript and being new to JS I am a bit stuck.
    Using the prompt dialogue box and a while loop statement where someone chooses a number between 1 and 100 inclusive.
    On clicking the OK button an Alert box comes up to tell the user after each guess if the number is less than or greater than their guess.

    It has also to keep track of the number of times the user guesses the number.

    So that if the user cancels of takes more than 7 guesses to guess the number the script should send out an Alert box telling them that they have lost the game. It then resets the counter to 0.

    If the user guesses the number within 7 tries the Alert box says Congratulations and resets the counter to 0.

    I wish to do the prompt method so that a user can play while they are downloading files.

    All Help Much Appreciated.

  • #2
    I understand the game, but I am not sure where you are stuck... Tell us where you are stuck and we will be able to help you out.

    PS: If you are asking us to write the whole script, then I have no time to do so
    Nobody is Perfect. I am Nobody.

    Comment


    • #3
      Originally posted by Unit


      PS: If you are asking us to write the whole script, then I have no time to do so
      I don't think anyone does. Did you read the sticky?

      Comment


      • #4
        The O/P has some script which can be referenced here..
        He/she should have posted to that thread rather than confusing things by starting a new one.

        .....Willy

        Comment


        • #5
          ah, I think I understand the next step now.. to get the input from a prompt instead of a text box..

          This is how you use a prompt

          var PlayerChoice = window.prompt("Enter your guess","");

          This will get the number that the player guessed into the PlayerChoice variable. you can use the variable just as you used the value in the text box document.f1.t1.value.
          Nobody is Perfect. I am Nobody.

          Comment


          • #6
            This is my original script

            <script language = "javaScript">
            <!--

            var guessme=Math.round(Math.random()*(99)+1);
            var speech='Guess my number (from 1 to 100)';

            function process(mystery) {
            var guess=document.forms.guessquiz.guess.value;
            var speech='"'+guess+ '" does not make sense to me.';
            document.forms.guessquiz.guess.value='';

            if (guess==mystery)
            {
            document.forms.guessquiz.prompt.value='Congratulations! '+mystery+' is correct!';
            alert ('Well done - the mystery number is '+mystery+'! \n\nPress this button to reload the page for another game.');
            speech='';
            document.location=document.location;
            }

            if (mystery<guess)
            {
            speech='Less than '+ guess;
            }

            if (mystery>guess)
            {
            speech='Greater than '+ guess;
            }

            if (guess=='')
            {
            speech='You didn\'t guess anything!'
            }

            document.forms.guessquiz.prompt.value=speech; document.forms.guessquiz.guess.focus();

            }

            </script>

            <FORM onSubmit="" NAME="guessquiz">

            <CENTER>
            <table align="center" bgcolor="#888888" border="3" cellpadding="5">
            <tr>
            <TD BGCOLOR="#004080">
            <font color="#ffffff" FACE="Arial"><B>GUESS MY NUMBER (1 - 100)</B></font>
            </td>
            </tr>
            <tr>
            <td>
            <center>
            <INPUT TYPE="text" NAME="prompt" SIZE="31" MAXLENGTH="40" VALUE="Guess my number (from 1 to 100)"><BR>
            <INPUT TYPE="text" NAME="guess" SIZE="3" MAXLENGTH="3" VALUE="">
            <INPUT TYPE="button" VALUE="Guess" onClick='process(guessme)'>
            </center>
            </td>
            </tr>
            </table>
            </center>

            </form>

            </script>

            Where I am stuck is that this script has it using a form.
            What I want is to use a prompt dialogue box instead. Also the messages back to the player to be in alert boxes.

            Also where would I put a counter to limit the player to 7 tries and then send out an alert box telling them this and then automatically resetting the counter to Zero.

            Your help would be very much appreciated.

            Comment

            Working...
            X