5 Replies - 1486 Views - Last Post: 05 September 2012 - 02:37 PM

#1 Mighty123e  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 05-September 12

Betakey generator for my game, Javascript

Posted 05 September 2012 - 12:55 PM

Hello there, I'm a bit new to coding and the forums. i decided to start by doing the tutorials on codecademy for javascript and html/jquery, for the basics and learn how to really start coding by making a fun cardgame in javascript,html5,canvas.

Now Currently all i want to happen is have a betakey generated, have it Pop up to tell me key, then store it in an array which can be accessed to check if the beta key you input was correct. I asked my brother to help me out and he said there was some information he could show me to help me but he is at work and won't be off for another 8 hours so hopefully you guys could help me out.

The problem currently is just that it wont generate the key and print out what it generated and im not sure exactly why, This is the code i have for generating the key.


function BetaKeyGen(){
 var Key = "";
 var Possiblekey = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
 var i;
 for(i = 0; i < 10; i++){
 	Key += Possiblekey.charAt(Math.floor(Math.random()* Possiblekey.length + 1));
 }
 return print(Key);
 
}





So hopefully you guy can help me out, and sorry for the text being a bit bigger its just so hard to see when its that small.

Is This A Good Question/Topic? 0
  • +

Replies To: Betakey generator for my game, Javascript

#2 CasiOo  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 1275
  • View blog
  • Posts: 2,837
  • Joined: 05-April 11

Re: Betakey generator for my game, Javascript

Posted 05 September 2012 - 01:05 PM

Wrong forum java != javascript

Your logic seems to work correctly. Try to run this script
		<script type="text/javascript">
			 var Key = "";
			 var Possiblekey = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
			 var i;
			 for(i = 0; i < 10; i++){
				Key += Possiblekey.charAt(Math.floor(Math.random()* Possiblekey.length + 1));
			 }
			
			alert(Key);
		</script>



We will have to see more code to solve the problem :)
Was This Post Helpful? 0
  • +
  • -

#3 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 8364
  • View blog
  • Posts: 31,076
  • Joined: 12-June 08

Re: Betakey generator for my game, Javascript

Posted 05 September 2012 - 01:07 PM

Moved from java to javascript..
Was This Post Helpful? 0
  • +
  • -

#4 Mighty123e  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 05-September 12

Re: Betakey generator for my game, Javascript

Posted 05 September 2012 - 01:09 PM

Well actually that was the only code so far, if it can't generate a key and print it then i'm sure if i can go farther.

Also when you say to run the script, where would i go about doing that, because currently im just using sublime text 2 as a text editor and the javascript developer console for chrome.
Was This Post Helpful? 0
  • +
  • -

#5 CasiOo  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 1275
  • View blog
  • Posts: 2,837
  • Joined: 05-April 11

Re: Betakey generator for my game, Javascript

Posted 05 September 2012 - 01:33 PM

Normally you want to insert your javascript as a script on your html page, I'm sure all tutorials start by telling about this?

<html>
	<head>
	</head>
	<body>
		<script type="text/javascript">
			var Key = "";
			var Possiblekey = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
			for(i = 0; i < 10; i++){
				Key += Possiblekey.charAt(Math.floor(Math.random()* Possiblekey.length + 1));
			}
		
			alert(Key);
		</script>
	</body>
</html>


Was This Post Helpful? 1
  • +
  • -

#6 Mighty123e  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 05-September 12

Re: Betakey generator for my game, Javascript

Posted 05 September 2012 - 02:37 PM

My tutorials didn't, i think its because i'm on the javascript section to just teach me all the basics, then next is html section where it probably combines them and shows me how to do it.

But i tested it now in the html and it did work so thanks, next step is to store it into an array and somehow access that array when they type in the key,

Ill try and figure that out by myself, Ill be back if i run into more problems, Thanks for the help again.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1