Closed Thread
Results 1 to 4 of 4

Thread: Please help with this code.

  1. #1
    expoit100 is offline Newbie
    Join Date
    Feb 2010
    Posts
    5
    Rep Power
    0

    Please help with this code.

    I need to understand and answer of this code. Please some one can learn me this code

    THE CODE:
    <script language=JavaScript>
    function checkPass()
    {
    var p1 = "ineedtounderstandthiscodehowitwork";
    var p2 = "bestowcautionintimesofmassownages";
    var p3 = "wassaidbyadudepseudodpsychomarine";

    var confirmPass = document.login.password.value;

    var chk0 = 0;
    var pass = "";
    var base = "";


    for ( a = 0; a < p1.length; ++a )
    {
    var blah = confirmPass.substring ( chk0, chk0 + 1 );
    var chk1 = p1.substring ( a, a + 1 );
    var chk2 = p2.substring ( a, a + 1 );
    var chk3 = p3.substring ( a, a + 1 );

    if ( chk1 == chk3 ) { if ( chk1 == blah) { base = base + chk1; } else { break; } chk0++; }
    if ( chk2 == chk1 ) { if ( chk2 == blah) { base = base + chk2; } else { break; } chk0++; }
    if ( chk3 == chk2 ) { if ( chk3 == blah) { base = base + chk3; } else { break; } chk0++; }
    ( p1.length == a + 1 ) ? pass = base : false;
    }

    ( confirmPass == pass ) ? window.location.href=pass+".php" : alert( "Wrong! Please try again." );

    }
    </script>
    please learn me how it work

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    cdg10620's Avatar
    cdg10620 is offline Programming Expert
    Join Date
    Jun 2009
    Location
    Texas
    Posts
    387
    Blog Entries
    3
    Rep Power
    12

    Re: Please help with this code.

    Quote Originally Posted by expoit100 View Post
    I need to understand and answer of this code. Please some one can learn me this code

    THE CODE:


    please learn me how it work
    Can you be a little more specific on what you are needing? Do you not understand what the function is doing?
    -CDG10620
    Software Developer

  4. #3
    expoit100 is offline Newbie
    Join Date
    Feb 2010
    Posts
    5
    Rep Power
    0

    Re: Please help with this code.

    yes i can not understand the fucntion what is doing.

    And i need to know what will be the script result.

    I mean this script for a password script in my we page but i can not understand what is password and how it work.

  5. #4
    cdg10620's Avatar
    cdg10620 is offline Programming Expert
    Join Date
    Jun 2009
    Location
    Texas
    Posts
    387
    Blog Entries
    3
    Rep Power
    12

    Re: Please help with this code.

    Quote Originally Posted by expoit100 View Post
    yes i can not understand the fucntion what is doing.

    And i need to know what will be the script result.

    I mean this script for a password script in my we page but i can not understand what is password and how it work.
    How about we teach you to fish instead...

    Below I spaced the code out a bit and changed the way the if statements are laid out. This may help you with reading the code. I also added a few comments.

    Code:
    function checkPass()
    		{
    			var p1 = "ineedtounderstandthiscodehowitwork";
    			var p2 = "bestowcautionintimesofmassownages";
    			var p3 = "wassaidbyadudepseudodpsychomarine";
    			
    			console.log( p1 );
    			console.log( p2 );
    			console.log( p3 );
    			
    			var confirmPass = document.login.password.value;
    			console.log( "confirmPass: " + confirmPass );
    			
    			var chk0 = 0;
    			var pass = "";
    			var base = "";
    
    
    			for ( a = 0; a < p1.length; ++a )
    			{
    				var blah = confirmPass.substring ( chk0, chk0 + 1 );
    				console.log( "blah: " + blah );
    				var chk1 = p1.substring ( a, a + 1 );
    				var chk2 = p2.substring ( a, a + 1 );
    				var chk3 = p3.substring ( a, a + 1 );
    				
    				console.log( chk1 );
    				console.log( chk2 );
    				console.log( chk3 );
    
    				if ( chk1 == chk3 ) 
    				{ 
    					if ( chk1 == blah) 
    						base = base + chk1; 
    					else 
    						break; 
    					
    					chk0++; 
    				}
    				
    				if ( chk2 == chk1 ) 
    				{ 
    					if ( chk2 == blah)
    						base = base + chk2;
    					else
    						break;
    						
    						chk0++; 
    				}
    				
    				if ( chk3 == chk2 ) 
    				{ 
    					if ( chk3 == blah)
    						base = base + chk3;
    					else
    						break;
    					
    					chk0++; 
    				}
    				
    				// This is basically an "if" statement
    				// if p1.lentgth is = a+1 then pass = base else false;
    				( p1.length == a + 1 ) ? pass = base : false;
    			}
    			
    			// This is an if statement as well
    			// if confirmPass == pass then window.location.href= pass+".php" else show alert message
    			// pass + ".php" is going to concatinate or join those values together
    			( confirmPass == pass ) ? window.location.href=pass+".php" : alert( "Wrong! Please try again." );
    		}
    Now... What you can do is take that function and place it in an html page. like this...

    HTML Code:
    <html>
    <head>
    	<script language="javascript">
    		function checkPass()
    		{
    			var p1 = "ineedtounderstandthiscodehowitwork";
    			var p2 = "bestowcautionintimesofmassownages";
    			var p3 = "wassaidbyadudepseudodpsychomarine";
    			
    			console.log( p1 );
    			console.log( p2 );
    			console.log( p3 );
    			
    			var confirmPass = document.login.password.value;
    			console.log( "confirmPass: " + confirmPass );
    			
    			var chk0 = 0;
    			var pass = "";
    			var base = "";
    
    
    			for ( a = 0; a < p1.length; ++a )
    			{
    				var blah = confirmPass.substring ( chk0, chk0 + 1 );
    				console.log( "blah: " + blah );
    				var chk1 = p1.substring ( a, a + 1 );
    				var chk2 = p2.substring ( a, a + 1 );
    				var chk3 = p3.substring ( a, a + 1 );
    				
    				console.log( chk1 );
    				console.log( chk2 );
    				console.log( chk3 );
    
    				if ( chk1 == chk3 ) 
    				{ 
    					if ( chk1 == blah) 
    						base = base + chk1; 
    					else 
    						break; 
    					
    					chk0++; 
    				}
    				
    				if ( chk2 == chk1 ) 
    				{ 
    					if ( chk2 == blah)
    						base = base + chk2;
    					else
    						break;
    						
    						chk0++; 
    				}
    				
    				if ( chk3 == chk2 ) 
    				{ 
    					if ( chk3 == blah)
    						base = base + chk3;
    					else
    						break;
    					
    					chk0++; 
    				}
    				
    				// This is basically an "if" statement
    				// if p1.lentgth is = a+1 then pass = base else false;
    				( p1.length == a + 1 ) ? pass = base : false;
    			}
    			
    			// This is an if statement as well
    			// if confirmPass == pass then window.location.href= pass+".php" else show alert message
    			// pass + ".php" is going to concatinate or join those values together
    			( confirmPass == pass ) ? window.location.href=pass+".php" : alert( "Wrong! Please try again." );
    		}
    
    	</script>
    </head>
    <body>
    	<input id="btn" runat="server" name="button" type="button" onclick="checkPass();" />
    </body>
    </html>
    Now... The "console" references are firefox specific and are meant to be used with an add on called "Firebug." If I were you I would paste that html code into notepad and save it on your machine as test.html. Then make sure you have firefox with firebug on your machine. Open the page in firefox and use the firebug "Console" feature to view the values being written to your console. This is a great way to debug javascript and see exactly what the code is doing.

    If you have any questions about that let me know.
    -CDG10620
    Software Developer

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Problem in a href location from php code to html code
    By newphpcoder in forum PHP Development
    Replies: 5
    Last Post: 05-13-2011, 02:03 PM
  2. how to make a bar code reader program in VB 2008 please send me the code
    By tontonskie in forum Visual Basic Programming
    Replies: 1
    Last Post: 11-15-2010, 12:58 AM
  3. add code for font size under php echo code
    By newphpcoder in forum PHP Development
    Replies: 2
    Last Post: 11-10-2010, 11:03 PM
  4. Code: Capture Code from USB Camera
    By MrNobody in forum Visual Basic Tutorials
    Replies: 71
    Last Post: 08-14-2009, 08:59 AM
  5. Code: Capture Code from USB Camera
    By MrNobody in forum Tutorials
    Replies: 5
    Last Post: 09-08-2007, 06:00 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts