0
People I’m doing a course and I can’t get past this exercise.
Write the function "medalText(number)", which takes a number as a parameter. Using only the maximum of an "if" only. Maybe arrays can be useful here.
You have to return the medal that corresponds to the first positions of a competition:
medalleDecordoComplesto (1) "gold" medalleDecordoComplesto (2) "silver" medalleDecordoComsto (3) "bronze" medalleDecordoComsto (4) "nothing" medalleDecordoComsto (5) "nothing"
function medalhaDeAcordoComPosto (numero){
var medalhas = ["ouro","prata", "bronze"];
numero= numero -1;
if (medalhas[numero] = "undefined"){
return "nada"
}else{
return medalhas[numero];
}
}
I’m using this code, but I get an error: The medal functionDecordoComPost(1) must return "gold" The medal functionDecordoComPost(2) must return "silver" The medal functionDecordoComPost(3) must return "bronze"
As far as I’m concerned, could someone help me understand what’s wrong with this code? Thank you very much.
You are assigning a value on
if
when using=
, use==
or===
for comparisons– Rafael Tavares
Even, have a question about this exercise if you have other questions, take a look there: Exercise taking the position of the array
– Rafael Tavares
So Raphael, I put the second=.

function medalhaDeAcordoComPosto (numero){
 var medalhas = ["ouro","prata", "bronze"];
 numero= numero -1;
 if (medalhas[numero] == "undefined"){
 return "nada"
 }else{
 return medalhas[numero];
 }

}

But now other errors appear: The medallion functionDeAgreementPost(4) should return "nothing" The medallion functionDecordoComplePost(45) should return "nothing" I saw your code and understood it, but I wanted to understand why mine is wrong yet, you could help me?– nehrso