1
I’m solving the exercise below, but I’m having some problems:
Write a suit functionDeruco, which given a suit, returns a list of strings, one for each card of this suit following the cards of the card. Ex:
naipeDeTruco("espadas")
["1 de espadas", "2 de espadas", "3 de espadas" ..., "12 de espadas"]
Remember that truco cards include all cards numbered 1 to 12, with the exception of cards 8 and 9.
Obs:
Remember that we will see as a result a set of strings, in this case, greatly respect the concatenation of spaces, and the uppercase and lowercase letters.
As a counter in this case you will have to create an array within the function. Similarly, you have to put each of the matching strings and at the end of the function you have to return the counter.
Remember not to put a specific data as a parameter, so our function has to serve all suits of the deck.
Here is my code:
function naipeDeTruco(naipe){
var arrayDeNaipes= [];
for (var i=1; i <=12; i++){
if((naipe == "espadas") && ([i]!=8) && ([i]!=9) && ([i]!=10)){
arrayDeNaipes.push([i]+ " de espadas");
}
else if((naipe == "paus") && ([i]!=8) && ([i]!=9) && ([i]!=10)){
arrayDeNaipes.push([i]+ " de paus");
}
else if((naipe == "copas") && ([i]!=8) && ([i]!=9) && ([i]!=10)){
arrayDeNaipes.push([i]+ " de copas");
}
else if((naipe == "ouro") && ([i]!=8) && ([i]!=9) && ([i]!=10)){
arrayDeNaipes.push([i]+ " de ouro");
}
}
return arrayDeNaipes;
}
Test my code on this site (https://jsfiddle.net/) and it’s working, it’s returning what’s expected:
However, when I will validate it on the digital house platform, the following error appears:
NOTE: In the statement it is requested that the numbers 8 and 9 are not returned. In my code, I put not to return the 8 and 9 and gave the error above. Then I modified it to not return 8, 9 and 10, but it gives the same error.
Does anyone know what might be going on?
your code doesn’t really return, you should talk to your course support to check the code on their side
– Ricardo Pontual
You can simplify that lot of
if
: https://jsfiddle.net/x54Lozfh/– hkotsubo
Hi @hkotsubo, thanks for the help. I did so below and passed the test.
function naipeDeTruco(naipe){
 var naipeEscolhido = naipe;

 var cartas = [
 "1 de "+naipeEscolhido, "2 de "+naipeEscolhido, "3 de "+naipeEscolhido, 
 "4 de "+naipeEscolhido, "5 de "+naipeEscolhido, "6 de "+naipeEscolhido, 
 "7 de "+naipeEscolhido, "10 de "+naipeEscolhido, "11 de "+naipeEscolhido, "12 de "+naipeEscolhido];

 return cartas;
 }

console.log(naipeDeTruco("espadas"));
– Bruno Ramos