-
Notifications
You must be signed in to change notification settings - Fork 66
Expand file tree
/
Copy path11-20.js
More file actions
112 lines (98 loc) · 2.91 KB
/
Copy path11-20.js
File metadata and controls
112 lines (98 loc) · 2.91 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/* 11 - Loja de ração */
function paymentOptions(price) {
let inCash = price - price * 0.1;
let creditCard = price + price * 0.15;
return `À Vista: R$${inCash} ou 4x de: R$${Math.round((creditCard / 4 * 100)) / 100}`;
}
/* 12 - Peso e preço do prato */
function weightAndValue(priceKg, plateWeight) {
let totalPrice = ((priceKg * plateWeight) / 1000).toFixed(2).replace('.', ',');
return `O prato de ${plateWeight} gramas custa: R$ ${totalPrice}`;
}
/* 13 - Cor aleatória */
function generateOneColor() {
let uniqueColor = Math.floor(Math.random() * 256);
return uniqueColor;
}
function randomRGBColor() {
let finalColor = `rgb(${generateOneColor()}, ${generateOneColor()}, ${generateOneColor()})`;
return finalColor;
}
/* 14 - Tempo de viagem */
function timeTravel(totalMinutes) {
let hours = Math.floor(totalMinutes / 60);
let minutes = totalMinutes % 60;
return (
"A viagem terá duração de " +
hours +
" hora(s) e " +
minutes +
" minuto(s)"
);
}
/* 15 - Área de uma circunferência */
function areaCircle(diameter) {
let radius = diameter / 2;
let area = Math.PI * Math.pow(radius, 2);
return `A circunferência de raio ${radius} cm possui uma área de ${area.toFixed(
2
)} cm quadrados`;
}
/* 16 - Verdadeiro ou falso? */
function randomBoolean() {
return Math.random() >= 0.5;
}
/* 17 - Financiamento de veículo */
function formatBrazilianMoney(number) {
const beforeComma = Math.floor(number);
let afterComma = Math.round(number * 100 - beforeComma * 100);
afterComma = afterComma !== 0 ? afterComma : `00`;
return `${beforeComma},${afterComma}`;
}
function carFinancing(carPrice, entranceValue, quota) {
let financing = carPrice - entranceValue;
let tax = 0.05;
return (
"Valor Financiado: R$" +
formatBrazilianMoney(financing) +
";\nValor do Juros: R$" +
formatBrazilianMoney(financing * tax) +
";\nQuantidade de Parcelas: " +
quota +
";\nValor da Parcela: R$" +
formatBrazilianMoney((financing * tax + financing) / quota) +
";\nValor Total do Carro: R$" +
formatBrazilianMoney(financing * tax + financing + entranceValue) + '.'
);
}
/* 18 - Simulação de dado RPG */
function rollDice(diceSide) {
let numberRolled = Math.floor(Math.random() * Number(diceSide) + 1);
return numberRolled;
}
/* 19 - Viagem de carro */
function carTrip(spBh, bhSal, salNat) {
let totalHours = spBh + bhSal + salNat;
let days = totalHours / 24;
return parseFloat(days.toFixed(3));
}
/* 20 - Aprovado ou reprovado? */
function avaliador(score1, score2, score3) {
let averageScore = Math.round((score1 + score2 + score3) / 3);
if (averageScore >= 6) {
return "Aprovação, média: " + averageScore;
}
return "Reprovação, média: " + averageScore;
}
module.exports = {
paymentOptions,
weightAndValue,
randomRGBColor,
timeTravel,
areaCircle,
randomBoolean,
carFinancing,
rollDice,
carTrip,
avaliador,
};