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.

2nd Sep 2018, 7:00 PM
Sevcan Doğramacı
Sevcan Doğramacı - avatar
3 Antworten
+ 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.
2nd Sep 2018, 10:40 PM
BraveHornet
BraveHornet - avatar
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
2nd Sep 2018, 7:22 PM
Lucia Frank
Lucia Frank - avatar
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.
3rd Sep 2018, 6:14 AM
Sevcan Doğramacı
Sevcan Doğramacı - avatar