I'm not able to do math operations with this function, obviously because it has char type elements inside.
var centesimas = 0;
function inicio() {
control = setInterval(cronometro, 10);
document.getElementById("inicio").disabled = true;
document.getElementById("parar").disabled = false;
document.getElementById("continuar").disabled = true;
document.getElementById("reinicio").disabled = false;
}
function parar() {
clearInterval(control);
document.getElementById("parar").disabled = true;
document.getElementById("continuar").disabled = false;
}
function reinicio() {
clearInterval(control);
centesimas = 0;
document.getElementById("Centesimas").innerHTML = "|00|"
document.getElementById("inicio").disabled = false;
document.getElementById("parar").disabled = true;
document.getElementById("continuar").disabled = true;
document.getElementById("reinicio").disabled = true;
}
function cronometro() {
if (centesimas < 999) {
centesimas++;
if (centesimas < 10) {
centesimas = "0" + centesimas
}
document.getElementById("Centesimas").innerHTML = ":" + centesimas;
}
if (centesimas == 999) {
centesimas = -1;
}
}
function resultado() {
document.getElementById("Result").innerHTML += document.getElementById("Centesimas").firstChild.data * 3;
}
<div id="contador">
<div class="reloj" id="Centesimas">:00</div>
<input type="button" class="boton" id="inicio" value="►" onclick="inicio();">
<input type="button" class="boton" id="parar" value="∎" onclick="parar();" disabled>
<input type="button" class="boton" id="continuar" value="↺" onclick="inicio();" disabled>
<input type="button" class="boton" id="reinicio" value="↻" onclick="reinicio();" disabled>
<input type="button" class="boton" id="resultado" value="Resultado" onclick="resultado();">
<div class="reloj" id="Result"></div>
</div>
It always returns NaN because of this, but I'd like to know if you can do this without removing char elements from within