Loop executes this function, why the value obtained is not accumulated

wants to change the opacity, of the element by constantly executing the timer, but only the opacity of the element obtained by the function each time is 0, which is not accumulated. The code is as follows:
function appear () {

   var opity = document.getElementById("fade-obj").style.opacity;  
   console.log(document.getElementById("fade-obj").style.opacity);    
    if(opity != 1) {   
        document.getElementById("fade-btn").disabled = "true";          
        opity += 0.2;
        document.getElementById("fade-obj").style.opacity = opity;
        setTimeout(appear,500);
    }else{
        document.getElementById("fade-btn").innerHTML = "";
        document.getElementById("fade-btn").removeAttribute("disabled");
    }
}
document.getElementById("fade-btn").addEventListener("click", function() {
      if (document.getElementById("fade-btn").innerHTML == "") {
        setTimeout(appear,500);
    }
}, false)

the results are as follows:

clipboard.png
I don"t know why the value of document.getElementById ("fade-obj") .style.opacity remains the same

Mar.21,2021

var opity = document.getElementById ('fade-obj'). Style.opacity
the value taken here is of string type
and then the + = becomes 0.20.2


var opity = document.getElementById('fade-obj').style.opacity;
//opity '0.2'
opity += 0.2; // '0.20.2'
document.getElementById('fade-obj').style.opacity = opity;
document.getElementById('fade-obj').style.opacity // 0.2
We must pay attention to the plus sign operation of

string!


in fact, you can debug and see it yourself, and you are more impressed than others to give you the answer directly

Menu