I have the code snippet exposed below:
var calcularSoma = function (primeiroValor, segundoValor) {
var soma = primeiroValor + segundoValor;
if (soma < 10) {
console.log(soma, "Unidades.");
return soma;
} else if (soma < 100) {
var restoUnidade = soma % 10;
var dezena = soma / 10;
if (restoUnidade == 1 && dezena <= 1) {
console.log(dezena, "Dezena. e ", restoUnidade, "Unidade");
} else {
console.log(dezena, "Dezenas. e ", restoUnidade, "Unidades");
}
return soma;
} else if (soma < 1000) {
var centena = soma / 100;
console.log(centena, "Centenas.");
return soma;
} else {
var milhar = soma / 1000;
console.log(milhar, "Milhar.");
return soma;
}
}
calcularSoma(5, 10);
1. What I intend is to display the result in the plural if the values contained in the variables are greater than 1. I will implement the conditions below, at the moment I need to first understand which implementation will represent the logic exposed.
2. I need to format the displayed value, in this example the value 1.5 Dezenas e 5 Unidades.
(plural of Unit is displayed, since the rest was greater than 1), I wanted to display something like: 1 Dezena e 5 Unidades.
/ p>
3. Here I used if(restoUnidade == 1 && dezena <= 1)
because in this example above the value of the tens variable in thesis is greater than 1, although it is a decimal.
P.S.: If possible tell me how best to expose the question, first the following code of the doubts (as exposed in this post), or the first questions followed by the code?