mercredi 10 juillet 2019

Multiple if-statements in function that returns different values. I want one to always return false

I have a function and in it there is multiple if-statements. All returns a string, but i want one of them to never execute if true.

 function render(num) {
   if(num < 5) return '';
   if(num >= 5 && num < 11) return '5+ ';
   if(num >= 11 && num < 21) return '10+ ';
   if(num >= 21 && num < 31) return '20+ ';
   if(num >= 31) return '30+ ';
 }

It is the first statement here that i want to - if true don't run the function. Now i just added an empty string but i don't wanna show anything. Because in the other statements there is also a text added after the string. So now it shows " number of members"

Is there anyway of doing this in this code or do i have to rewrite a lot?

Aucun commentaire:

Enregistrer un commentaire