0
I’m not being able to do mathematical operations with this function, obviously because there are char 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 on account of this, but and would like to know if you have how to do without removing the char type elements from within
SUAVARIABLE.replace(/[ 0-9.]+/g, '); will replace non-numeric characters.
– edson alves
Could you put the code in full? It looks like it came without some parts. If possible, add HTML as well.
– Woss
Opa, it was bad people my internet fell, I edited and, this code already exists on the Internet, I only modified according to something I’m doing just for learning, I started messing with javascript has not 3 months
– Jefter Rocha
@edsonalves Descupe, I have no idea how it works : but I’ll look into
– Jefter Rocha