I'm very new to JavaScript and to coding in general. I'm creating an animation that expands and contract an image to simulate breathing. I am also adding a "breath count" to count the number of breaths. This is the code I used to create the breath count:
<h1> Breath Number: <span id= "countingBreaths">0</span> </h1>
Then in the script tag:
//function for breath number increase
var countingTo = function() {
countingBreaths.textContent = 1 + (parseFloat(countingBreaths.textContent));
var startCounting = setInterval(countingTo, 4000);
var stopCounting = function () {
clearInterval(startCounting);
}
stopButton.addEventListener("click", stopCounting);
}
startButton.addEventListener("click", countingTo);
My problem is in the parseFloat function. My intention is to increase the breath number by 1 (+1). But, instead, it is doubling my number (1, 2, 4, 8, 16, 32, etc). I'm not sure what I did wrong. I've tried everything and looked on this site for help but can't find any information. I'd really appreciate the help!