Created
August 16, 2017 14:15
-
-
Save joaocarvalhowd/f1e7e662ae3c56be1b0a0c66a4af417a to your computer and use it in GitHub Desktop.
Pace calc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Função para calcular ritmo | |
function ritmoMinutos() { | |
//Verifica campo nulo | |
if(document.ritmo.km.value == ""){ | |
alert("Informe a distância"); | |
document.ritmo.km.focus(); | |
return false; | |
} | |
//Verifica se campos horas ou minutos estão nulos | |
else if(document.ritmo.h.value == "00" && document.ritmo.min.value == "00"){ | |
alert("Informe: horas ou minutos"); | |
return false; | |
} | |
//Verifica se valores digitados em minutos está entre 0-59 | |
else if(document.ritmo.min.value > 59){ | |
alert("Digite minutos entre 0-59"); | |
return false; | |
} | |
//Verifica se valores digitados em segundos está entre 0-59 | |
else if(document.ritmo.seg.value > 59){ | |
alert("Digite segundos entre 0-59"); | |
return false; | |
} | |
//Verifica se foi digitado somente números | |
else if((isNaN(document.ritmo.km.value))||(isNaN(document.ritmo.h.value))||(isNaN(document.ritmo.min.value))||(isNaN(document.ritmo.seg.value))){ | |
alert("Digite somente números"); | |
return true; | |
} | |
//Variáveis | |
var km = eval(document.ritmo.km.value); | |
var hora = eval(document.ritmo.h.value); | |
var min = eval(document.ritmo.min.value); | |
var seg = eval(document.ritmo.seg.value); | |
//Calculos | |
if (seg < 60 & min < 60){ | |
seg = seg * 1; | |
seg = seg + min * 60 + hora * 60 * 60; | |
ritseg = seg / km / 60; | |
pacemin = ritseg - ritseg % 1; | |
paceseg = ritseg % 1 * 0.6 * 100; | |
paceseg = paceseg - paceseg % 1; | |
} | |
if (paceseg < 10){ | |
paceseg = "0" + paceseg; | |
} | |
if (pacemin < 10){ | |
pacemin = "0" + pacemin; | |
} | |
if (pacemin > 1 ){ | |
document.ritmo.resultado.value = pacemin + ":" + paceseg +" min/km"; | |
} | |
if(km > 1){ | |
document.ritmo.resultado.value = pacemin + ":" + paceseg +" min/km"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment