feat: Add JavaScript core exercises and solutions
- Implemented exercises for array high-order methods, memory and execution, switch statements, and final review. - Added starter and answer files for each exercise to facilitate learning. - Created a runner HTML file to execute JavaScript code and display console outputs. - Updated README files to include exercise objectives, tasks, and usage instructions.
This commit is contained in:
28
03-javascript-core/03-operators-and-conditions/README.md
Normal file
28
03-javascript-core/03-operators-and-conditions/README.md
Normal file
@@ -0,0 +1,28 @@
|
||||
# 练习 3:运算符和条件判断
|
||||
|
||||
## 目标
|
||||
|
||||
学会比较数据,并根据不同条件输出不同结果。
|
||||
|
||||
## 你要练什么
|
||||
|
||||
- 算术运算符
|
||||
- 比较运算符
|
||||
- 逻辑运算符
|
||||
- `if...else if...else`
|
||||
|
||||
## 任务
|
||||
|
||||
请完成一个“成绩评级”脚本,要求:
|
||||
|
||||
- 根据分数计算是否及格
|
||||
- 根据分数输出等级
|
||||
- 90 分及以上为 A
|
||||
- 80 到 89 为 B
|
||||
- 60 到 79 为 C
|
||||
- 60 以下为 D
|
||||
|
||||
## 文件
|
||||
|
||||
- [starter.js](/Users/lijiaqing/home/wwwroot/front-end-example/03-javascript-core/03-operators-and-conditions/starter.js)
|
||||
- [answer.js](/Users/lijiaqing/home/wwwroot/front-end-example/03-javascript-core/03-operators-and-conditions/answer.js)
|
||||
18
03-javascript-core/03-operators-and-conditions/answer.js
Normal file
18
03-javascript-core/03-operators-and-conditions/answer.js
Normal file
@@ -0,0 +1,18 @@
|
||||
const score = 86;
|
||||
|
||||
let passed = score >= 60;
|
||||
let grade = "";
|
||||
|
||||
if (score >= 90) {
|
||||
grade = "A";
|
||||
} else if (score >= 80) {
|
||||
grade = "B";
|
||||
} else if (score >= 60) {
|
||||
grade = "C";
|
||||
} else {
|
||||
grade = "D";
|
||||
}
|
||||
|
||||
console.log("分数:", score);
|
||||
console.log("是否及格:", passed);
|
||||
console.log("等级:", grade);
|
||||
@@ -0,0 +1,9 @@
|
||||
const score = 86;
|
||||
|
||||
// 任务:
|
||||
// 1. 用布尔值保存是否及格
|
||||
// 2. 用 if...else if...else 判断等级
|
||||
// 3. 输出分数、是否及格、等级
|
||||
|
||||
let passed = false;
|
||||
let grade = "";
|
||||
Reference in New Issue
Block a user