
Originally Posted by
kayut
HI,
How can I rewrite this with Ternary Operator?
Code:
face.textContent = result == 0 ? headNr + ' times ' + resultFace : tailNr + ' times ' + resultFace;
I tried everything, but couldn't find a way.
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?
Code:
var headNr = "aaaa";
var resultFace = "bbbb";
var tailNr = "cccc";
var test = result == 1 ? headNr + ' times ' + resultFace : tailNr + ' times ' + resultFace;
console.log(test);
result=0
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.
Bookmarks