0
Help me execute this code correctly please!
Now that you know enough Javascript, the jury of a programming asked us to develop the medallion function which returns the medal corresponding to the positions, according to the following logic:
first place: corresponds to "gold"second place: corresponds to "silver" third place: corresponds to "bronze" other places: corresponds "Continue participating"
If we execute the function with the following positions, the result would be thus:
medallion GunPost(1) "gold" medallion Gunpowder(2) "silver" medalleSecondOPost(3) "bronze" medalleSecondOPost(5) "Continue participating"
Set the medallion functionSecond and returns a text according to the parameter. Tip: in this function you can use several if.
I wrote the following code:
var posicoes = ["continue participando", "ouro", "prata", "bronze"];
function medalhaSegundoOPosto(numero) {
if (numero >= posicoes.length) {
return "continue participando";
} {
return posicoes[numero];
}
}
console.log(medalhaSegundoOPosto(1));
console.log(medalhaSegundoOPosto(2));
console.log(medalhaSegundoOPosto(3));
console.log(medalhaSegundoOPosto(4));
console.log(medalhaSegundoOPosto(9));
When run appears the following errors:
Execution of the medallion functionSecondOPost(4) must return 'Continue participating'
Execution of the medallion functionSecondOPost(9) must return 'Continue participating'
Continue participando
is different fromcontinue participando
– Rafael Tavares
I copied and pasted the code you wrote. I executed it. It worked perfectly. Using console.log(medalNumberOPost()) with parameters from 0 to 9, the output was exactly as expected: { 0 : 'continue participating', 1 : 'gold', 2 : 'silver', ... } and anyone from the third returns 'continue participating''.
– Felipe Maia