Skip to content

Commit 72ac5b6

Browse files
committed
laco de repetições
1 parent a045756 commit 72ac5b6

File tree

4 files changed

+74
-0
lines changed

4 files changed

+74
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
const contas = [22,295,176,440,37,105,10,1100,86,52]
2+
3+
let totalGorjeta = valor => valor >= 50 && valor <= 300 ? valor * (15/100) : valor * (20/100);
4+
5+
let gorjeta = [];
6+
for (let i = 0; i < contas.length; i++){
7+
gorjeta.push(totalGorjeta(contas[i]));
8+
}
9+
10+
11+
12+
let valorTotalDaConta = (contas, gorjeta)=> contas + gorjeta;
13+
14+
15+
let total = [];
16+
for(let i = 0; i < contas.length && i < gorjeta.length; i++) {
17+
total.push(valorTotalDaConta(contas[i], gorjeta[i]));
18+
}
19+
20+
for(let i = 0; i < contas.length && i < gorjeta.length && i < total.length; i++) {
21+
console.log(`O valor total da conta de R$ ${contas[i]} + gorjeta de R$ ${gorjeta[i]} é R$ ${total[i]}.`);
22+
}
23+
24+
function calcAverage(arr){
25+
let sum = 0;
26+
for(let i = 0; i < arr.length; i++){
27+
sum += arr[i];
28+
}
29+
30+
return sum / arr.length;
31+
}
32+
33+
console.log(`
34+
Média dos numeros contidos no array: ${calcAverage(contas)}
35+
`)

02-Fundamentals-Part-2/starter/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,6 @@
2626
<body>
2727
<h1>JavaScript Fundamentals – Part 2</h1>
2828
<script src="script.js"></script>
29+
<script src="loopWhile.js"></script>
2930
</body>
3031
</html>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// const pessoa = {
2+
// nome : 'Genildo',
3+
// sobrenome : 'Cerqueira',
4+
// anoNascimento : 2023 - 1992,
5+
// job : 'Analista',
6+
// amigos : ['Rafaela', 'Gabriel', 'Breno']
7+
// }
8+
9+
const pessoa = ['Jonas','Santos',2023-1992, ['Rafael','Gabriel','Maria'], true]
10+
11+
//Loop de trás pra frente
12+
for(let i = pessoa.length - 1; i >= 0; i-- ){
13+
console.log(i, pessoa[i]);
14+
}
15+
16+
//Loop aninhado
17+
for(let exe = 1; exe <= 3; exe++){
18+
console.log(`Serie de exercicios ${exe}`);
19+
for(let i = 0; i < 15; i++){
20+
console.log(`Exercicio ${exe}: Repetição do exercicio ${i}`);
21+
}
22+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/* let cout = 2;
2+
while (cout <=10){
3+
console.log(cout);
4+
cout ++
5+
} */
6+
7+
8+
9+
let dados = Math.trunc(Math.random() * 6) + 1;
10+
console.log(dados);
11+
12+
while (dados !== 6){
13+
console.log(`Você tirou ${dados}`)
14+
dados = Math.trunc(Math.random() * 6) + 1
15+
if(dados === 6) console.log('Saiu 6, loop while encerrado')
16+
}

0 commit comments

Comments
 (0)