Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis0
Can you help me to use if-else statements with arrow functions?
I want to create an arrow functions which will multiply the parameter by 2 if the taken value is even , if not , will multiply by 3 and reassign the values to previous ones.
3 Respostas
+ 2
var func = (value) => (value%2==0)?value*2:value*3;
This is the short way to do this.
You can also do this with if else.
0
If- else
se evalĆŗa la expresiĆ³n lĆ³gica que se planteo a continuaciĆ³n del if y si es distinta de cero (verdadera) se realizan las acciones indicadas a continuaciĆ³n; si la expresiĆ³n lĆ³gica es cero (falso) se realizan las acciones a continuaciĆ³n del else. En esta estructura la salida por cero(falso) puede obviarse; en tal caso, si la expresiĆ³n arroja cero (falso) no se ejecutarĆ” acciĆ³n alguna
0
Minecraft Destroyer HD I tried it but the assigning the new values to the previous values part didn't work, after some search I have just found
value => value = (value%2==0)? value*2:value*3;
and it worked ,but thank you for helping since I was also complicated about the general syntax of arrow functions with conditions.