diff --git a/client/i18n/locales/english/intro.json b/client/i18n/locales/english/intro.json index 06b9666611f..0c2b08d7ee1 100644 --- a/client/i18n/locales/english/intro.json +++ b/client/i18n/locales/english/intro.json @@ -3104,6 +3104,13 @@ "In these lessons you will learn about the number type, arithmetic operators, and using them with numbers and strings." ] }, + "lab-debug-type-coercion-errors": { + "title": "Debug Type Coercion Errors in a Buggy App", + "intro": [ + "In this lab, you will be working with a buggy app that contains several type coercion errors.", + "Your task is to identify and fix these errors to ensure the application functions correctly." + ] + }, "lecture-working-with-operator-behavior": { "title": "Working with Operator Behavior", "intro": [ diff --git a/client/src/pages/learn/full-stack-developer/lab-debug-type-coercion-errors/index.md b/client/src/pages/learn/full-stack-developer/lab-debug-type-coercion-errors/index.md new file mode 100644 index 00000000000..064e4d9eb47 --- /dev/null +++ b/client/src/pages/learn/full-stack-developer/lab-debug-type-coercion-errors/index.md @@ -0,0 +1,9 @@ +--- +title: Introduction to the Debug Type Coercion Errors in a Buggy App +block: lab-debug-type-coercion-errors +superBlock: full-stack-developer +--- + +## Introduction to the Debug Type Coercion Errors in a Buggy App + +In this lab, you will be working with a Buggy App that contains several type coercion errors. Your task is to identify and fix these errors to ensure the application functions correctly. diff --git a/curriculum/challenges/english/blocks/lab-debug-type-coercion-errors/68f890b73bbfc9efa7379e7b.md b/curriculum/challenges/english/blocks/lab-debug-type-coercion-errors/68f890b73bbfc9efa7379e7b.md new file mode 100644 index 00000000000..d3033020312 --- /dev/null +++ b/curriculum/challenges/english/blocks/lab-debug-type-coercion-errors/68f890b73bbfc9efa7379e7b.md @@ -0,0 +1,179 @@ +--- +id: 68f890b73bbfc9efa7379e7b +title: Debug Type Coercion Errors in a Buggy App +challengeType: 26 +dashedName: debug-type-coercion-errors-in-a-buggy-app +--- + +# --description-- + +You've just joined a local web development shop, and your first assignment is to clean up some buggy code left behind by the previous developers. + +They were attempting simple arithmetic operations, but something went wrong, the results don't make sense. Your task is to review, debug, and correct the code so it performs as expected and is easier to read. + +**Objective:** Fulfill the user stories below and get all the tests to pass to complete the lab. + +**User Stories:** + +1. You should have a variable named `firstResult` that correctly adds the numbers `5` and `10` to produce the value `15`. +2. You should have a variable named `secondResult` that correctly subtracts `5` from `8` to produce the value `3`. +3. You should have a variable named `thirdResult` that produces the value `6` by adding two numbers. Replace the boolean currently used in the expression with a number. +4. You should have a variable named `fourthResult` that produces the value `8` by adding two numbers. Replace the boolean currently used in the expression with a number. +5. You should have a variable named `fifthResult` that correctly multiplies two numbers to get the product `20`. Replace the string currently used in the expression with a number. +6. You should have a variable named `sixthResult` that correctly adds two numbers to produce the value `22`. Replace the `null` currently used in the expression with a number. + +# --hints-- + +You should have a variable called `firstResult`. + +```js +assert.match(code, /const\s+firstResult\s*=/); +``` + +`firstResult` should have the numeric value `15`. + +```js +assert.strictEqual(firstResult, 15); +``` + +You should have a variable called `secondResult`. + +```js +assert.match(code, /const\s+secondResult\s*=/); +``` + +`secondResult` should have the numeric value `3`. + +```js +assert.strictEqual(secondResult, 3); +``` + +You should have a variable called `thirdResult`. + +```js +assert.match(code, /const\s+thirdResult\s*=/); +``` + +`thirdResult` should have the numeric value `6`. + +```js +assert.strictEqual(thirdResult, 6); +``` + +`thirdResult` should not include a boolean value (`true` or `false`). + +```js +const match = code.match(/const\s+thirdResult\s*=\s*([^;]+)/); +assert.isNotNull(match); +const expression = match[1]; +assert.notMatch(expression, /\btrue\b|\bfalse\b/); +``` + +You should have a variable called `fourthResult`. + +```js +assert.match(code, /const\s+fourthResult\s*=/); +``` + +`fourthResult` should have the numeric value `8`. + +```js +assert.strictEqual(fourthResult, 8); +``` + +`fourthResult` should not include a boolean value (`true` or `false`). + +```js +const match = code.match(/const\s+fourthResult\s*=\s*([^;]+)/); +assert.isNotNull(match); +const expression = match[1]; +assert.notMatch(expression, /\btrue\b|\bfalse\b/); +``` + +You should have a variable called `fifthResult`. + +```js +assert.match(code, /const\s+fifthResult\s*=/); +``` + +`fifthResult` should have the numeric value `20`. + +```js +assert.strictEqual(fifthResult, 20); +``` + +`fifthResult` should not include a string multiplication (e.g. "10" * 2). + +```js +const match = code.match(/const\s+fifthResult\s*=\s*([^;]+)/); +assert.isNotNull(match); +const expression = match[1]; +assert.notMatch(expression, /["'`].*["'`]\s*\*/); +``` + +You should have a variable called `sixthResult`. + +```js +assert.match(code, /const\s+sixthResult\s*=/); +``` + +`sixthResult` should have the numeric value `22`. + +```js +assert.strictEqual(sixthResult, 22); +``` + +`sixthResult` should not include `null` in its expression. + +```js +const match = code.match(/const\s+sixthResult\s*=\s*([^;]+)/); +assert.isNotNull(match); +const expression = match[1]; +assert.notMatch(expression, /\bnull\b/); +``` + +# --seed-- + +## --seed-contents-- + +```js +const firstResult = 5 + "10"; +console.log(`5 + 10 = ${firstResult}`); + +const secondResult = "Eight" - 5; +console.log(`8 - 5 = ${secondResult}`); + +const thirdResult = true + 5; +console.log(`1 + 5 = ${thirdResult}`); + +const fourthResult = false + 8; +console.log(`0 + 8 = ${fourthResult}`); + +const fifthResult = "10" * 2; +console.log(`10 * 2 = ${fifthResult}`); + +const sixthResult = null + 22; +console.log(`0 + 22 = ${sixthResult}`); +``` + +# --solutions-- + +```js +const firstResult = 5 + 10; +console.log(`5 + 10 = ${firstResult}`); + +const secondResult = 8 - 5; +console.log(`8 - 5 = ${secondResult}`); + +const thirdResult = 1 + 5; +console.log(`1 + 5 = ${thirdResult}`); + +const fourthResult = 0 + 8; +console.log(`0 + 8 = ${fourthResult}`); + +const fifthResult = 10 * 2; +console.log(`10 * 2 = ${fifthResult}`); + +const sixthResult = 0 + 22; +console.log(`0 + 22 = ${sixthResult}`); +``` diff --git a/curriculum/structure/blocks/lab-debug-type-coercion-errors.json b/curriculum/structure/blocks/lab-debug-type-coercion-errors.json new file mode 100644 index 00000000000..16c9c942db0 --- /dev/null +++ b/curriculum/structure/blocks/lab-debug-type-coercion-errors.json @@ -0,0 +1,15 @@ +{ + "name": "Debug Type Coercion Errors in a Buggy App", + "isUpcomingChange": false, + "dashedName": "lab-debug-type-coercion-errors", + "helpCategory": "JavaScript", + "blockLayout": "link", + "blockLabel": "lab", + "usesMultifileEditor": true, + "challengeOrder": [ + { + "id": "68f890b73bbfc9efa7379e7b", + "title": "Debug Type Coercion Errors in a Buggy App" + } + ] +} diff --git a/curriculum/structure/superblocks/full-stack-developer.json b/curriculum/structure/superblocks/full-stack-developer.json index cd1f9255f63..5b19031a59c 100644 --- a/curriculum/structure/superblocks/full-stack-developer.json +++ b/curriculum/structure/superblocks/full-stack-developer.json @@ -307,6 +307,7 @@ "dashedName": "javascript-booleans-and-numbers", "blocks": [ "lecture-working-with-numbers-and-arithmetic-operators", + "lab-debug-type-coercion-errors", "lecture-working-with-operator-behavior", "lecture-working-with-comparison-and-boolean-operators", "lecture-working-with-unary-and-bitwise-operators",