【发布时间】:2021-02-04 14:55:14
【问题描述】:
if (props.name == "Computer"){
if (result == "Won"){
result = "Lost";
}
else if (result == "Lost"){
result = "Won";
}
}
尝试转换为三进制,但没有成功。 (不知道如何混淆第一行和第二行)。 此外,不确定“不知道该放什么”这个地方。
result =="Won" ? result="Lost": result=="Lost" ? result="Won" : <HAVE NO IDEA WHAT TO PUT>;
【问题讨论】:
-
为什么需要三元运算符。
if-else块中的代码更具可读性 -
只是想练习一下三元算子。
标签: javascript if-statement conditional-operator