Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <body>
- <input type="text" id="wartosc" value="">
- <input type="submit" onclick="oceny()"/>
- <p>Oceny: <div id="oceny"></div>
- <p>Srednia: <div id="srednia"></div>
- <script>
- var a =[];
- function oceny(){
- var ocena = document.getElementById("wartosc").value;
- var error = 0;
- if(ocena>6){
- alert("Ocena nie moze byc wieksza niz 6")
- error=1;
- }
- if(ocena<1){
- alert("Ocena nie moze byc mniejsza niz 1")
- error=1;
- }
- if(error==0){
- document.getElementById("oceny").innerHTML += "<b>"+ocena+" </b>"
- a.push(parseInt(ocena))
- var srednia = 0;
- for(var ile=0; ile<a.length; ile++){
- srednia = srednia + a[ile];
- }
- var IleLiczb = a.length;
- srednia = srednia / IleLiczb;
- document.getElementById("srednia").innerHTML = srednia;
- }
- }
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement