0
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 Answers
+ 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.