【发布时间】:2015-12-03 19:39:36
【问题描述】:
这是我目前拥有的代码:
if (isStandard(statement)) {
if (isPerfect(statement)) {
alert("This is a perfect palindrome.");
} else {
alert("This is a standard palindrome.");
}
} else {
alert("The statement is not a palindrome.");
}
我希望能够将其转换为单个三元语句,其中 alert() 中的字符串将是返回的值。我知道如何对 if-elseif-else 语句执行此操作,但不适用于嵌套 if。
【问题讨论】:
-
为什么还要这样做,你的代码这样可读性更强
-
通过查看您的代码,我认为它是 if else 语句与 if 中的另一个 if else 语句
标签: javascript if-statement ternary-operator simplify