Advertisement
Guest User

Untitled

a guest
May 29th, 2015
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta name="description" content="[add your bin description]">
  5. <meta charset="utf-8">
  6. <title>JS Bin</title>
  7. </head>
  8. <body>
  9. <form name="formularz">
  10. Wartość początkowa<br>
  11. <input type="text" id="Poczatkowa" ><br>
  12.  
  13. Wartosc koncowa<br>
  14. <input type="text" id="Koncowa" >
  15.  
  16. <input type="button" value="Liczby pierwsze" onClick="liczbypierwsze();">
  17.  
  18. <br>Wynik:<br>
  19. <textarea name="Wynik" rows="1" cols="21"></textarea>
  20.  
  21. </form>
  22. <script id="jsbin-javascript">
  23. function liczbypierwsze(){
  24. var x = document.getElementById("Poczatkowa").value;
  25. var y = document.getElementById("Koncowa").value;
  26.  
  27.  
  28. if(y<2) {
  29. document.formularz.Wynik.value = 'Nie ma liczb pierwszych w tym przedziale';
  30. }
  31. else {
  32. for(x;x<=y;x++) {
  33. for(i=2;i<=x;i++){
  34. if (x === i) {
  35. document.formularz.Wynik.value += x+' ';
  36. } else {
  37. if (x%i === 0) {
  38. break;}
  39. }
  40. }
  41. }
  42. }
  43. }
  44. </script>
  45.  
  46.  
  47.  
  48. <script id="jsbin-source-javascript" type="text/javascript">function liczbypierwsze(){
  49. var x = document.getElementById("Poczatkowa").value;
  50. var y = document.getElementById("Koncowa").value;
  51.  
  52.  
  53. if(y<2) {
  54. document.formularz.Wynik.value = 'Nie ma liczb pierwszych w tym przedziale';
  55. }
  56. else {
  57. for(x;x<=y;x++) {
  58. for(i=2;i<=x;i++){
  59. if (x === i) {
  60. document.formularz.Wynik.value += x+' ';
  61. } else {
  62. if (x%i === 0) {
  63. break;}
  64. }
  65. }
  66. }
  67. }
  68. }
  69. </script></body>
  70. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement