JavaScript Javascript - Progress Bar not Working

I have a progress bar, and I have my js getting the value of it with document.getElementsByTagName(progressbar)[num]. I have this in multiple functions, but when one of the progress bars are removed, the others don't continue because num is set... How do I fix this?

function plantTree()
{
    if(water > 10){
        var doSome = doSom;
        doSom++;
        water -= 10;
        var div = document.getElementById("plantATree");
        div.innerHTML = "<progress val='0' max='100'></progress>";
        var i = 0;
        var inte = setInterval(function(){
            document.getElementsByTagName("progress")[doSome].value += 5;
            i++;
            if(i >= 20){
                window.clearInterval(inte);
            }
        },1000);
        var inter = setInterval(function(){
            var progVal = document.getElementsByTagName("progress")[doSome].value;
            if (progVal >= 100){
                statusTwoUpdate("You have finished Planting a Tree...", "wood += 5");
                window.clearInterval(inter);
                div.innerHTML = "Plant a Tree";
                doSom--;
            }
        },500);
    }else{
        statusTwoUpdate("You tried and failed...", "water -= 6");
    }
}

EDIT: Here is a like to all the javascript I use: http://hastebin.com/gucuwaxema.coffee

Answer:1

I have a question which I still haven't found the answer to. When I use this method to capture a mouse up event: <div onmouseup="/*Script to be executed*/"></div> Is that more ...

I have a question which I still haven't found the answer to. When I use this method to capture a mouse up event: <div onmouseup="/*Script to be executed*/"></div> Is that more ...

  1. javascript addeventlistener onmouseup
  2. window addeventlistener onmouseup
  3. js addeventlistener onmouseup
  4. document addeventlistener onmouseup

What is the purpose of the above line of code. I'm specifically confused by OR-ing the 'function() {}'. Why the empty function? To give a little more context to the line of code, here is the more ...

What is the purpose of the above line of code. I'm specifically confused by OR-ing the 'function() {}'. Why the empty function? To give a little more context to the line of code, here is the more ...

I've read half a dozen articles on improving performance with ng-repeat and so far I can't find a straight forward way at improving rendering of a simple bind once table. I've profiled various ...

I've read half a dozen articles on improving performance with ng-repeat and so far I can't find a straight forward way at improving rendering of a simple bind once table. I've profiled various ...

I'm stuck on a making a simple loading function for an AJAX request. AJAX is still pretty new to me, so I'm sure I'm just doing something dumb! ajaxStart fires and starts loading the spinner.gif, ...

I'm stuck on a making a simple loading function for an AJAX request. AJAX is still pretty new to me, so I'm sure I'm just doing something dumb! ajaxStart fires and starts loading the spinner.gif, ...