-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathaula06.01_exercicio2.html
More file actions
38 lines (27 loc) · 876 Bytes
/
aula06.01_exercicio2.html
File metadata and controls
38 lines (27 loc) · 876 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<!doctype html>
<html>
<head>
<title>Logica de Programação Javascript</title>
<meta charset="utf-8">
</head>
<body>
<h1>Lógica de programação com Javascript</h1>
</body>
<script>
var numeros = new Array(1, 2, 3, 5, 2);
//mostrar na tela a soma dos números pares da array acima
var somaDosPares = somaOsPares(numeros);
alert('a soma é: ' + somaDosPares);
function somaOsPares(arr){
var soma = 0;
for(var i = 0; i < arr.length; i++){
console.log(i);
console.log(arr[i]);
if( !isNaN(arr[i]) && arr[i] % 2 === 0){
soma += arr[i];
}
}
return soma;
}
</script>
</html>