Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <head>
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
- </head>
- <body>
- <p>Wpisz tekst</p>
- <input type="text" id="tekst" value="" autofocus><br>
- <button id="zatwierdz">Zatwierdz</button><br>
- <p id="1"></p>
- <p id="2"></p>
- <p id="3"></p>
- <p id="4"></p>
- <p id="5"></p>
- </body>
- <script>
- $(document).ready(function(){
- $("#zatwierdz").click(function() {
- var tekst = $("#tekst").val();
- if (isPalindrome(tekst))
- $("#1").html("Tekst jest palindromem");
- else $("#1").html("Tekst nie jest palindromem");
- $("#2").html("Ilosc znakow: " + tekst.length);
- $("#3").html("Ilosc bialych znakow: " + (tekst.length - tekst.replace(/ /g,'').length));
- if($.isNumeric(tekst))
- {
- if (parseInt(tekst) % 2 == 0) {
- $("#4").html("Liczba parzysta");
- }
- else $("#4").html("Liczba nieparzysta");
- if(isPrime(tekst))
- $("#5").html("Liczba pierwsza");
- else $("#5").html("Nie jest liczba pierwsza");
- }
- else $("#4").html("Nie jest liczba");
- });
- });
- function isPrime(x){
- var prime=true;
- for(var i=2;i<=Math.sqrt(x);i++){
- if(x%i===0){
- prime=false;
- }
- }
- if(prime){
- return true;
- }
- };
- function isPalindrome(s) {
- var dlugosc = s.length;
- for (var i = 0; i < (dlugosc/2); ++i) {
- if (s.charAt(i) != s.charAt(dlugosc - i - 1)) {
- return false;
- }
- }
- return true;
- };
- </script>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement