jeudi 4 février 2021

Trying to convert if else statement into ternary in javascript

if (props.name == "Computer"){
        if (result == "Won"){
            result = "Lost";
        }
        else if (result == "Lost"){
            result = "Won";
        }
    }

Tried converting to ternary, but failed to do so. (Have no idea how to mix up the first and second line). Also, not sure about "HAVE NO IDEA WHAT TO PUT" this spot.

result =="Won" ? result="Lost": result=="Lost" ? result="Won" : <HAVE NO IDEA WHAT TO PUT>;

Aucun commentaire:

Enregistrer un commentaire