HI,
How can I rewrite this with Ternary Operator?
I tried everything, but couldn't find a way.Code:face.textContent = result == 0 ? headNr + ' times ' + resultFace : tailNr + ' times ' + resultFace;
Thanks
Printable View
HI,
How can I rewrite this with Ternary Operator?
I tried everything, but couldn't find a way.Code:face.textContent = result == 0 ? headNr + ' times ' + resultFace : tailNr + ' times ' + resultFace;
Thanks
You're already using a ternary operator? I tested your code and it appeared to work fine for me.
What is exact problem you're having?
result=0Code:var headNr = "aaaa";
var resultFace = "bbbb";
var tailNr = "cccc";
var test = result == 1 ? headNr + ' times ' + resultFace : tailNr + ' times ' + resultFace;
console.log(test);
cccc times bbbb
result=1
aaaa times bbbb
Just a quick note. In situations like these its usually better to write out the full code so that it is easy to manage in the future, rather than compressing it down.