Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


JavaScrip/Html codiing help!

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Crossrocket.1
Master Cheater
Reputation: 0

Joined: 16 Nov 2007
Posts: 307

PostPosted: Fri Nov 21, 2008 8:08 pm    Post subject: JavaScrip/Html codiing help! Reply with quote

I need to write code for my HTML class..
I tried my best but I need your help ive got till monday.
Teacher's req.
BTW: She gives a b If u have everything
(2): If u hand in one day late its one grade down
and this will be one day late on monday. So I need extra to get an A and then dropped down to a B.
Teachers instructions:
Code:

Project #4
M256 Computer Programming
Guessing Game

Using HTML and JavaScript, write a program that will generate a random integer between 1 and 100 then have the user guess the number. Give clues to help the user guess.

Specific Requirements:


1. Draw a sketch of what your web page will look like.-Done

2. On the sketch, indicate what event handlers will be used (onClick on button, etc.). Write pseudo-code for the function logic.-Done

3. On the web page, include the following:

a. Clear instructions for the user on how to play the game.-Done

b. A button for the user to click to start the game.-Done

c. A button for the user to click to check his guess.-Done

d. A button for the user to start over (use a confirm box). Be sure to reset all values (including totals)-Done

e. A textbox to display the number of guesses-Done

f. A textbox to display the number of wins (the user wins when he guesses the number)-Done

4. Do all processing in functions.

5. Generate a random integer between 1 and 100 for the user to guess.-Done

6. If the user guesses the correct number, display an appropriate ‘congratulations’ message and update all totals accordingly.

7. When the user ‘wins’, automatically generate a new number to play again.

8. If the user guesses incorrectly, display an appropriate message to tell the user to guess higher or lower the next time, then update all totals accordingly.

9. Keep track of the number of times the user guesses and display this in the appropriate textbox.

10. Keep track of the number of times the user wins the game and display this in the appropriate textbox.

11. Include appropriate comments in your source code.-Done

Possible enhancements:
-Only allow 5 guesses (if the user is wrong on the 5th guess, he ‘loses’ the game)
-Don’t let the user guess the same number twice (alert them that they’ve already guessed that number)
-Custom buttons
-enhanced formatting (choice of numbers, etc.)
-Other ideas???


My Java code. Please only use like low lvl javascript stuff i have used in my code i know urs will be faster but i need noobie code.:
Code:

<html>
<head><link rel='stylesheet' type='text/css'href='exampleStyle.css'>
<title>Guessin' game</title>


<body background = "AWESOMENESS.jpg">
<script language="Javascript">

      function resetGame() //function to confirm the reset
      {
         var confirmReset = window.confirm("Are you sure you want to reset the game?");
         if(confirmReset == true)//sees if the user clicked yes and resets
         {
            frmGss.reset()
            alert ("Your form has been reset")
         } else                  //alert boxes
         {
            alert   ("Your form has not been reset")
         }
      }
     
      function generateNum(frmGss) //function to generate a random number
      {
         var ranNum = Math.round(Math.random()*100);
         alert("Your random number is " + ranNum);
         
         if(ranNum == frmGss.txtGues)
         {
            alert ("You rule");
     
         }else
         {
            alert ("WRONG");
         }
     
   
}
         





</script>
</head>
<body>

<form name=frmGss>
<td><tr><p><center>Instructions<br><!--instructions-->
1. Guess a number between 1-100 and enter it in the textbox<br>
2. Click play<br>
The computer just generated a random number for you and now, will check if you guessed right<br>
You will be getting tips on either your guess was higher/lower and if its near<br>
3. Keep guessing until you win!<br>
Your wins will also be told to you!<br><br><br><br><br><br><br><br>
<div id="container">
<img src="guess.bmp" align=center border=2>
<br><br><br><br><br><br><br>
Enter a guess between 1-100:

<input type=text name=txtGues size=3 maxlength=3 value="0">

<input class="butts" type="button" value="Play!" onClick="generateNum(frmGss)"/><br><br><br><br><br>
Number of Guesses:

<input type=text name=txtGues2 size=5 maxlength=20  value="0" readonly="readonly">
<br>
Number of times you guessed right:
<input type=text name=txtGues3 size=5 maxlength=20  value="0" readonly="readonly">

<input class="butts" type="button" value="Reset" onClick="resetGame(frmGss);"/><br><br><br><br><br>



</div>
</form>
</body>
</html>

_________________
Back to top
View user's profile Send private message
Reak
I post too much
Reputation: 0

Joined: 15 May 2007
Posts: 3496

PostPosted: Sat Nov 22, 2008 5:48 am    Post subject: Reply with quote

Code:
<html>
<head><link rel='stylesheet' type='text/css'href='exampleStyle.css'>
<title>Guessin' game</title>
<body background = "AWESOMENESS.jpg">
<script language="Javascript">
var guessed = 0;
var wins = 0;
var fails = 0;
var gnumbers = new Array();

   function resetGame() //function to confirm the reset
   {
      var confirmReset = window.confirm("Are you sure you want to reset the game?");
      if(confirmReset == true)//sees if the user clicked yes and resets
      {
         guessed = 0;
         wins = 0;
         fails = 0;
         updateStats();
         document.getElementById('resultDiv').style.display = "none";
         document.getElementById('playbtn').disabled = false;
         alert ("Your form has been reset")
      }
   }
     
   function generateNum() //function to generate a random number
   {
      if(guessed > 4){
         ShowRank();
         return;
      }
      var ranNum = Math.round(Math.random()*100);
      var gues = document.getElementById('txtGues').value;
      if(gues < 0 || gues > 100){
         alert("Only numbers between 0-100");
         return
      }
      for(var i=1; i<6; i++){
         if(gnumbers[i] == gues){
            alert("You tried it with this number already, chose another!");
            return;
         }
      }
      
      alert("Your random number is " + ranNum);
      guessed += 1;
      if(ranNum == gues)
      {
         wins += 1;
         updateStats();
         alert ("Correct! You rule xD");
      } else {
         var difference;
         fails += 1;
         updateStats();
         if(ranNum > gues){
            difference = ranNum-gues;
            if(difference < 6){
               alert("Wrong, your guessed number was lower! But you were very close!");
            } else {
               alert("Wrong, your guessed number was lower!");
            }
         } else {
            difference = gues-ranNum;
            if(difference < 6){
               alert("Wrong, your guessed number was higher! But you were very close!");
            } else {
               alert("Wrong, your guessed number was higher!");
            }
         }
      }
      gnumbers[guessed] = gues;
      if(guessed > 4){
         document.getElementById('playbtn').disabled = true;
         ShowRank()
      }
      
   }
   
   function ShowRank(){
         var rank;
         alert("Game Over! You've used up all your 5 guess chances. Result:");
         if(wins > 4)
            rank = "You were ALWAYS right! Your Rank: God.";
         else if(wins > 3)
            rank = "You were almost always right! Your Rank: Very very nice.";
         else if(wins > 2)
            rank = "You were almost always right! Your Rank: Very good.";
         else if(wins > 1)
            rank = "You were almost always right! Your Rank: Nice.";
         else if(wins > 0)
            rank = "You were almost always right! Your Rank: Good.";
         else
            rank = "You were always wrong. Your Rank: Loser.";
         alert(rank);
         document.getElementById('resultDiv').innerHTML = "Game Over! You've used up all your 5 guess chances. Result:<br>"+rank+"<br><b>Click Reset to restart the game!</b><br><br>";
         document.getElementById('resultDiv').style.display = "";
         return;
   }
   
   function updateStats(){
      document.getElementById('nOfGuesses').value = guessed;
      document.getElementById('nOfWins').value = wins;
      document.getElementById('nOfFails').value = fails;
   }
   
   function keyPressHandler(e){
      if(e.which == 13)
         generateNum();
   }
</script>
</head>
<body>

<p><center>Instructions<br><!--instructions-->
1. Guess a number between 1-100 and enter it in the textbox<br>
2. Click play<br>
The computer just generated a random number for you and now, will check if you guessed right<br>
You will be getting tips on either your guess was higher/lower and if its near<br>
3. Keep guessing until you win!<br>
Your wins will also be told to you!</p><br><br><br><br><br><br><br><br>
<div id="container">
   <img src="guess.bmp" align="center" border="2">
   <br><br><br><br><br><br><br>
   
   <b>Enter a guess between 1-100:</b> <input type="text" onkeypress="keyPressHandler(event)" name="txtGues" id="txtGues" size="3" maxlength="3" value="0">
   <input class="butts" name="playbtn" id="playbtn" type="button" value="Play!" onClick="generateNum()"/><br><br><br><br><br>
   <div id="resultDiv" style="display: none">Game Over! You've used up all your 5 guess chances. Result:<br>
   </div>
   <b>Number of Guesses:</b> <input type="text" name="nOfGuesses" id="nOfGuesses" size="5" maxlength="20"  value="0" readonly="readonly"><br>
   <b>Number of times you guessed right:</b> <input type="text" name="nOfWins" id="nOfWins" size="5" maxlength="20"  value="0" readonly="readonly"><br>
   <b>Number of times you guessed wrong:</b> <input type="text" name="nOfFails" id="nOfFails" size="5" maxlength="20"  value="0" readonly="readonly"><br>
   <input class="butts" type="button" value="Reset" onClick="resetGame();"/><br><br><br><br><br>
</div>

</body>
</html>


Good luck.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites