# 章序号/节序号/节/笔记序号 codecademy, Condition # 概念阐释 - if...else的缩写格式 - 首先给出变量值,再给出条件 ## 语法 ```js 变量名称?真值if: 假值else; ``` ![](http://image.harryrou.wiki/2023-01-16-%E6%88%AA%E5%B1%8F2023-01-16%2008.01.50.png) - **问号 `?` 后面是true** - **冒号`:` 后面是false** - **第一个冒号前没有分号,因为句子没有结尾** # 举例子 # 类比、比较与对比 [[js condition if else语句]] # 问题 用三元运算符的简写形式写出下列代码: *hint: 注意don't引号的使用, 注意分号的使用。注意语法格式。* **1.** ```js let isLocked = false; if (isLocked) { console.log('You will need a key to open the door.'); } else { console.log('You will not need a key to open the door.'); } ``` **2.** ```js let isCorrect = true; if (isCorrect) { console.log('Correct!'); } else { console.log('Incorrect!'); } ``` **3.** ```js let favoritePhrase = 'Love That!'; if (favoritePhrase === 'Love That!') { console.log('I love that!'); } else { console.log("I don't love that!"); } ``` # 问题答案 - 当string里使用了**单引号**时,string可以换成**双引号**,或者字符加`\`, 例如:`It\'s` # 备注(经验集/错误集) ## 错误集: - 语法格式写错了