0
Write a function that given a total of years of study returns how experienced the user is:
<script>
function experiencia(anos) {
switch (anos) {
case anos >= 0 && anos < 1:
return 'Iniciante'
case anos >= 1 && anos < 3:
return 'Intermediário'
case anos >= 3 && anos < 6:
return 'Avançado'
case anos >= 7:
return 'Jedi Master'
}
}
var anosEstudo = 7;
var final = experiencia(anosEstudo);
console.log(final)
</script>
The ending gives Undefined, which is wrong?
Are you using the
switch
in the wrong way. In this case, it seems to me to make more sense to useif
andelse
even– Rafael Tavares