1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
<!DOCTYPE html> <html> <head> <title>2016 jesień 1</title> <meta charset="utf-8"> </head> <body> <form> Twoje hasło <input type="password" id="haslo"> <button type="button" onclick="sprawdz()">Sprawdź</button> <p id="komunikat"></p> <script> function sprawdz() { //pobieramy tekst var tekst=document.getElementById('haslo').value; //badamy długośc tekstu var dl=tekst.length; //sprawdzamy czy w haśle jest cyfra a będzie jeśli licznik będzie większy od 0 var licznik=0; for ( var i=0;i<=dl;i++) { if (tekst.charCodeAt(i)>=48&&tekst.charCodeAt(i)<58)licznik++; } //jeśli nie wiemy jaka jest długość hasła i czy zawiera cyfry pozostało ogłosić wyniki if (tekst=="") { document.getElementById('komunikat').innerHTML="Wpisz hasło"; document.getElementById('komunikat').style.color="red"; } else if (dl>7&&licznik>0) { document.getElementById('komunikat').innerHTML="dobre"; document.getElementById('komunikat').style.color="green"; } else if ((dl>=4)&&(dl<=6)&&licznik>0) { document.getElementById('komunikat').innerHTML="średnie"; document.getElementById('komunikat').style.color="blue"; } else { document.getElementById('komunikat').innerHTML="słabe"; document.getElementById('komunikat').style.color="yellow"; } } </script> </form> </body> </html> |