...

View Full Version : Resolved JavaScript Game (Game 1)



RSHowat
07-12-2011, 09:08 PM
Ok so i want to work on an EASY basic game. As simple as Guess what number... But there are some twist...

Ok So here is my example...

(HTML, i know this.)I'm Guessing a number 1-99. What is it?

(java) Lets say its 66 and they guess 53, have the text rusult be in a pop up window be: Too low!

(java) Lets say they guess 78, have the text rusult be in a pop up window be: Too high!

(java) Lets say they guess 100+, have the text rusult be in a pop up window be: Out of range!

(java)But lets say they guess 66, have a text result be in a pop up window be: You've won!

(java) I want a text field where you can enter your answer, and it will do the actions above.

Can anyone code this?
Thanks for reading! :)

alykins
07-12-2011, 09:15 PM
I'm wondering if this is an assignment? I'll point you in a direction and help you begin to be able to start the code

you need to have a pass the typed answer to the function and then analyze the answer in regards to the value. then use if statements to determine an alert and alert the user accordingly.

even if not assignment need to see some code that you've done

RSHowat
07-12-2011, 09:18 PM
Its not, this is personal. Well i barley know java but i can post what i know but its not a whole lot...

alykins
07-12-2011, 09:23 PM
random number (http://www.javascriptkit.com/javatutors/randomnum.shtml)
pass info from filed to function (http://www.quackit.com/javascript/tutorial/javascript_functions.cfm)

then do something to show you are working on developing the analytical section... you will need if statements. also your game2 post (if i remeber the thread correctly will simply be a modification of this

RSHowat
07-12-2011, 09:58 PM
These links should help, can you get on your Yahoo IM so i can get your live help please? :)

alykins
07-12-2011, 09:59 PM
oh... try again- i blocked... need to let me know before IM'ing me- i didn't know it was anyone "real"

RSHowat
07-12-2011, 10:27 PM
making this public, this is what alykins and I solved, need some error fixing, doesn't seem to be working.


<html>
<head>
<title>JSTEST</title>
<script type="text/javascript">
function FinNum(guess){
if (guess == 62) alert ("Your guess is correct!")
else (guess >= 62) alert ("Your guess is too high!")
else (guess <= 62) alert ("Your guess is too low!")
else alert ("Your guess is out of range!")
</script>
</head>
<body>
<form>
I'm guessing a number 1-99. What is it?
<br />
<input type="input" name="yourGuess" />
<input
type="button"
onclick="FinNum(guess)"
value="Guess" />
</form>
</body>
</html>

alykins
07-13-2011, 12:13 AM
really? did you not think i would get back online and see this? this is literally the exact "from the top of my head" script i fired through messenger. You need to work with this and figure out the proper syntax's yourself. I am assuming after this post *and I hope* that no one will assist you further until you do some work on your own.

bullant
07-13-2011, 12:25 AM
onclick="FinNum(guess)"Where are you getting guess from in the above line?

Also, I would convert the number string you pass to the function to a number data type using the Number() object.

And since you are not submitting the data anywhere, the <form> is actually redundant.

alykins
07-13-2011, 12:28 AM
onclick="FinNum(guess)"Where are you getting guess from in the above line?

Also, I would convert the number string you pass to the function to a number data type using the Number() object.

because this is really incomplete... it incorporates the flow path i have in my head and i gave him this, literally line for line in a chat window as a way to guide him. i didn't fill in all the gaps- i assumed he was going to take this and use it to research how to do it; not just re-post as his code and state that he jointly developed it... i am slightly annoyed right now.

Edit: and to the OP- you also let out key info i told you to make... i told you to make a var finNum... and i told you it had a purpose... i'm not going to tell you again why i told you to make it and what it was for; but it had to do with my second response to your post

bullant
07-13-2011, 12:46 AM
I was replying to the code posted by the OP (post 7) assuming he/she wrote it.

I have no way of knowing with certainty who actually wrote that code and who actually wrote it is irrelevant to me.

RSHowat
07-13-2011, 02:28 AM
Just lock this post. I'll mark it as solved. -.-



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum