mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-09-24 23:01:18 +08:00
feat(curriculum): add debug increment/decrement operator lab (#63134)
Co-authored-by: Jessica Wilkins <67210629+jdwilkin4@users.noreply.github.com> Co-authored-by: Ilenia <26656284+ilenia-magoni@users.noreply.github.com>
This commit is contained in:
co-authored by
Jessica Wilkins
Ilenia
parent
c0dc4d59ae
commit
206c992321
@@ -3123,6 +3123,13 @@
|
||||
"In these lessons you will learn about operator precedence, the increment and decrement operators, and compound assignment operators."
|
||||
]
|
||||
},
|
||||
"lab-debug-increment-and-decrement-operator-errors": {
|
||||
"title": "Debug Increment and Decrement Operator Errors in a Buggy App",
|
||||
"intro": [
|
||||
"In this lab, you'll debug an application that has several errors related to the increment and decrement operators.",
|
||||
"Your task is to identify and fix the errors so that the application works as intended."
|
||||
]
|
||||
},
|
||||
"lecture-working-with-comparison-and-boolean-operators": {
|
||||
"title": "Working with Comparison and Boolean Operators",
|
||||
"intro": [
|
||||
@@ -8648,14 +8655,8 @@
|
||||
"title": "Nasal Finals",
|
||||
"intro": ["", ""]
|
||||
},
|
||||
"zh-a1-review-pinyin": {
|
||||
"title": "Pinyin Review",
|
||||
"intro": ["", ""]
|
||||
},
|
||||
"zh-a1-quiz-pinyin": {
|
||||
"title": "Pinyin Quiz",
|
||||
"intro": ["", ""]
|
||||
},
|
||||
"zh-a1-review-pinyin": { "title": "Pinyin Review", "intro": ["", ""] },
|
||||
"zh-a1-quiz-pinyin": { "title": "Pinyin Quiz", "intro": ["", ""] },
|
||||
"zh-a1-warm-up-greeting-new-colleagues": {
|
||||
"title": "Greeting New Colleagues",
|
||||
"intro": ["", ""]
|
||||
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
---
|
||||
title: Introduction to the Debug Increment and Decrement Operator Errors in a Buggy App
|
||||
block: lab-debug-increment-and-decrement-operator-errors
|
||||
superBlock: full-stack-developer
|
||||
---
|
||||
|
||||
## Introduction to the Debug Increment and Decrement Operator Errors in a Buggy App
|
||||
|
||||
In this lab, you will be working with a buggy app that contains several increment and decrement operator errors. Your task is to identify and fix these errors to ensure the application functions correctly.
|
||||
+133
@@ -0,0 +1,133 @@
|
||||
---
|
||||
id: 69008059d43d6751385883c1
|
||||
title: Debug Increment and Decrement Operator Errors in a Buggy App
|
||||
challengeType: 26
|
||||
dashedName: debug-increment-and-decrement-operator-errors-in-a-buggy-app
|
||||
---
|
||||
|
||||
# --description--
|
||||
|
||||
Your friend has asked you to help them debug their code. They are practicing increment and decrement operators but are getting unexpected results in the console.
|
||||
|
||||
Your task is to help them identify the mistakes and update the code so that the console outputs match the expected results.
|
||||
|
||||
You can refer back to the prior lessons on increment and decrement operators as well as prefix and postfix notation.
|
||||
|
||||
**User Stories:**
|
||||
|
||||
1. You should have a variable named `updatedCounter` that correctly produces the value `11` by using the increment operator. Update the expression to use the correct prefix or postfix notation instead of hardcoding the value.
|
||||
2. You should have a variable named `finalScore` that correctly produces the value `8` by using the increment operator. Update the expression to use the correct prefix or postfix notation instead of hardcoding the value.
|
||||
3. You should have a variable named `updatedCoins` that correctly produces the value `2` by using the decrement operator. Update the expression to use the correct prefix or postfix notation instead of hardcoding the value.
|
||||
4. You should have a variable named `newHealth` that correctly produces the value `7` by using the decrement operator. Update the expression to use the correct prefix or postfix notation instead of hardcoding the value.
|
||||
|
||||
# --hints--
|
||||
|
||||
You should have a variable named `updatedCounter` that uses prefix increment notation (`++counter`).
|
||||
|
||||
```js
|
||||
assert.match(code, /updatedCounter\s*=\s*\+\+counter\s*;/);
|
||||
assert.strictEqual(typeof updatedCounter, 'number');
|
||||
```
|
||||
|
||||
`updatedCounter` should equal to `11`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(updatedCounter, 11);
|
||||
```
|
||||
|
||||
You should have a variable named `finalScore` that uses postfix increment notation (`score++`).
|
||||
|
||||
```js
|
||||
assert.match(code, /finalScore\s*=\s*score\+\+\s*;/);
|
||||
assert.strictEqual(typeof finalScore, 'number');
|
||||
```
|
||||
|
||||
`finalScore` should equal to `8`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(finalScore, 8);
|
||||
```
|
||||
|
||||
You should have a variable named `updatedCoins` that uses prefix decrement notation (`--coins`).
|
||||
|
||||
```js
|
||||
assert.match(code, /updatedCoins\s*=\s*--coins\s*;/);
|
||||
assert.strictEqual(typeof updatedCoins, 'number');
|
||||
```
|
||||
|
||||
`updatedCoins` should equal to `2`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(updatedCoins, 2);
|
||||
```
|
||||
|
||||
You should have a variable named `newHealth` that uses postfix decrement notation (`health--`).
|
||||
|
||||
```js
|
||||
assert.match(code, /newHealth\s*=\s*health--\s*;/);
|
||||
assert.strictEqual(typeof newHealth, 'number');
|
||||
```
|
||||
|
||||
`newHealth` should equal to `7`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(newHealth, 7);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
let counter = 10;
|
||||
console.log(`Counter is currently ${counter}`);
|
||||
|
||||
let updatedCounter = counter++;
|
||||
console.log(`Counter is now ${updatedCounter}`);
|
||||
|
||||
let score = 8;
|
||||
console.log(`Score is currently ${score}`);
|
||||
|
||||
let finalScore = ++score;
|
||||
console.log(`Score is still ${finalScore}`);
|
||||
|
||||
let coins = 3;
|
||||
console.log(`Coins is currently ${coins}`);
|
||||
|
||||
let updatedCoins = coins--;
|
||||
console.log(`Coins is now ${updatedCoins}`);
|
||||
|
||||
let health = 7;
|
||||
console.log(`Health is currently ${health}`);
|
||||
|
||||
let newHealth = --health;
|
||||
console.log(`Health is still ${newHealth}`);
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
let counter = 10;
|
||||
console.log(`Counter is currently ${counter}`);
|
||||
|
||||
let updatedCounter = ++counter;
|
||||
console.log(`Counter is now ${updatedCounter}`);
|
||||
|
||||
let score = 8;
|
||||
console.log(`Score is currently ${score}`);
|
||||
|
||||
let finalScore = score++;
|
||||
console.log(`Score is still ${finalScore}`);
|
||||
|
||||
let coins = 3;
|
||||
console.log(`Coins is currently ${coins}`);
|
||||
|
||||
let updatedCoins = --coins;
|
||||
console.log(`Coins is now ${updatedCoins}`);
|
||||
|
||||
let health = 7;
|
||||
console.log(`Health is currently ${health}`);
|
||||
|
||||
let newHealth = health--;
|
||||
console.log(`Health is still ${newHealth}`);
|
||||
```
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "Debug Increment and Decrement Operator Errors in a Buggy App",
|
||||
"isUpcomingChange": false,
|
||||
"dashedName": "lab-debug-increment-and-decrement-operator-errors",
|
||||
"helpCategory": "JavaScript",
|
||||
"blockLayout": "link",
|
||||
"blockLabel": "lab",
|
||||
"usesMultifileEditor": true,
|
||||
"challengeOrder": [
|
||||
{
|
||||
"id": "69008059d43d6751385883c1",
|
||||
"title": "Debug Increment and Decrement Operator Errors in a Buggy App"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -310,6 +310,7 @@
|
||||
"lecture-working-with-numbers-and-arithmetic-operators",
|
||||
"lab-debug-type-coercion-errors",
|
||||
"lecture-working-with-operator-behavior",
|
||||
"lab-debug-increment-and-decrement-operator-errors",
|
||||
"lecture-working-with-comparison-and-boolean-operators",
|
||||
"lecture-working-with-unary-and-bitwise-operators",
|
||||
"lecture-working-with-conditional-logic-and-math-methods",
|
||||
|
||||
Reference in New Issue
Block a user