Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="">
- <head>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <link rel="stylesheet" href="style.css"/>
- <title>Javascript</title>
- </head>
- <body style="text-align:center">
- <div id="tlo">
- <h1>Suma kolejnych liczb całkowitych</h1>
- <form>
- <p>Podaj Liczbę Początkową</p>
- <input type="text" id="P"></input>
- <p>Podaj Liczbę Końcową</p>
- <input type="text" id="K"></input>
- <button onclick="whiles();return false;">While</button>
- <button onclick="dowhile();return false;">Do-While</button>
- <button onclick="fore();return false;">For</button>
- </form>
- <div>Wyniki</div>
- <p>Pętla While</p><div id="wynik"></div>
- <p>Pętla Do-While</p><div id="wynik1"></div>
- <p>Pętla For</p><div id="wynik2"></div>
- </div>
- <script>
- function whiles()
- {
- var a = parseFloat(document.getElementById("P").value);
- var b = parseFloat(document.getElementById("K").value);
- var suma = 0;
- while(b>=a)
- {
- suma+=a;
- a++;
- }
- document.getElementById("wynik").innerHTML = suma;
- }
- function dowhile()
- {
- var a = parseFloat(document.getElementById("P").value);
- var b = parseFloat(document.getElementById("K").value);
- var suma = 0;
- do
- {
- suma+=a;
- a++;
- }
- while(b>=a);
- document.getElementById("wynik1").innerHTML = suma;
- }
- function fore()
- {
- var a = parseFloat(document.getElementById("P").value);
- var b = parseFloat(document.getElementById("K").value);
- var suma = 0;
- for (var i = a; i<=b; i++)
- {
- suma =(suma+i);
- }
- document.getElementById("wynik2").innerHTML = suma;
- }
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment