I am trying to start using shorthand javascript in my code and I am not very adept at it yet. I was trying to convert my if...else statements to ternary if...else. I am getting an error when I try.
Javascript:
if (x.includes(name)) {
metric_val = funcOne(a);
} else if (y.includes(name)) {
metric_val = funcTwo(a);
}
Ternary if...else
let metric_val = (x.includes(name)) ? funcOne(a) : (y.includes(name)) ? funcTwo(a);
Error:
Uncaught SyntaxError: Unexpected token ;
What am I doing wrong?
Aucun commentaire:
Enregistrer un commentaire