这可以用三目运算法写吗
4 回答

千秋此意
TA贡献158条经验 获得超187个赞
var num = operator === '+' ? num1 + num2 : operator === '-' ? num1 - num2 : operator === '*' ? num1 * num2 : operator === '/' ? num1 / num2 : num;
可以是可以不过这种情况用if语句或者switch都比三目好多了,望采纳~
添加回答
举报
0/150
提交
取消