Created
December 1, 2012 22:10
-
-
Save DeividSaenz/4185522 to your computer and use it in GitHub Desktop.
Practica2: Suma numeros pares hasta 'n'
This file contains 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
function sumaPares(n){ //'n' es el número (parámetro) en el que se detendrá la función | |
var num = 0; | |
for (var i = 0; i <= n; i++) { | |
if (i>0) { //Sólo si 'i' ya no es cero entra, para no dividir entre cero | |
if ((i%2)==0) { //Si el residuo de la división entre dos es igual a cero, es por que es par | |
num=num+i; | |
console.log(i+"+"); | |
}; | |
}; | |
}; | |
return "="+num; | |
} | |
console.log(sumaPares(10)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hay algún errorcillo de sintaxis, lo has probado?
En clase lo vemos.