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<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>
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.
Now... What you can do is take that function and place it in an html page. like this...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... 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.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>
If you have any questions about that let me know.
-CDG10620
Software Developer
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks