Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>MaxMin</title>
- <style type="text/css">
- div{
- margin-bottom: 10px;
- }
- </style>
- </head>
- <body>
- <div id="container">
- </div>
- <div>
- <input class="numbers" type="text" id="inp">
- <input type="button" value="Избриши">
- </div>
- <div>
- <input type="button" value="Додади" onclick="add();">
- </div>
- <div>
- <input type="button" value="Пресметај" onclick="calculate();">
- </div>
- <div>
- <span id="average"></span>
- <span id="max"></span>
- <span id="min"></span>
- </div>
- <script>
- function add() {
- var inp = document.createElement('input');
- inp.setAttribute('type','text');
- inp.setAttribute('class','numbers');
- var btn = document.createElement('input');
- btn.setAttribute('type','button');
- btn.setAttribute('value','Избриши');
- document.getElementById('container').appendChild(inp);
- document.getElementById('container').appendChild(btn);
- }
- var max = 0 ;
- var min = 999999;
- var sum =0;
- var length;
- function calculate() {
- var fields = document.getElementsByClassName('numbers');
- length = fields.length;
- for(var i = 0 ; i < fields.length ; i++){
- if(fields[i].value > max){
- max = fields[i].value;
- }
- if(fields[i].value < min){
- min = fields[i].value;
- }
- sum += parseInt(fields[i].value);
- console.log(sum);
- }
- document.getElementById('average').innerHTML = "Просек: " + sum/length;
- document.getElementById('max').innerHTML = "Максимум: " + max;
- document.getElementById('min').innerHTML = "Минимум: " + min;
- }
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement