From 6c3bc14f52ebd7e0a895dba42915785c4a8b85bb Mon Sep 17 00:00:00 2001 From: Ilenia <26656284+ilenia-magoni@users.noreply.github.com> Date: Thu, 25 Sep 2025 16:29:14 +0200 Subject: [PATCH] feat(curriculum): add Build an All-True Property Validator lab (#62198) Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Sem Bauke --- client/i18n/locales/english/intro.json | 6 + .../lab-all-true-property-validator/index.md | 9 + .../a10d2431ad0c6a099a4b8b52.md | 181 ++++++++++++++++++ .../lab-all-true-property-validator.json | 15 ++ .../superblocks/full-stack-developer.json | 1 + 5 files changed, 212 insertions(+) create mode 100644 client/src/pages/learn/full-stack-developer/lab-all-true-property-validator/index.md create mode 100644 curriculum/challenges/english/blocks/lab-all-true-property-validator/a10d2431ad0c6a099a4b8b52.md create mode 100644 curriculum/structure/blocks/lab-all-true-property-validator.json diff --git a/client/i18n/locales/english/intro.json b/client/i18n/locales/english/intro.json index 455b88ece0c..55fac651b41 100644 --- a/client/i18n/locales/english/intro.json +++ b/client/i18n/locales/english/intro.json @@ -3576,6 +3576,12 @@ "In this lab you will create a function that can flatten deeply nested arrays, handling any level of nesting without using built-in flat methods." ] }, + "lab-all-true-property-validator": { + "title": "Build an All-True Property Validator", + "intro": [ + "In this lab you will build a function that checks if all objects in an array have a truthy value for a specific property." + ] + }, "review-javascript-higher-order-functions": { "title": "JavaScript Higher Order Functions Review", "intro": [ diff --git a/client/src/pages/learn/full-stack-developer/lab-all-true-property-validator/index.md b/client/src/pages/learn/full-stack-developer/lab-all-true-property-validator/index.md new file mode 100644 index 00000000000..0da05a3d742 --- /dev/null +++ b/client/src/pages/learn/full-stack-developer/lab-all-true-property-validator/index.md @@ -0,0 +1,9 @@ +--- +title: Introduction to the Build an All-True Property Validator +block: lab-all-true-property-validator +superBlock: full-stack-developer +--- + +## Introduction to the Build an All-True Property Validator + +For this lab, you will create a function that validates whether all objects in an array have a truthy value for a specific property. diff --git a/curriculum/challenges/english/blocks/lab-all-true-property-validator/a10d2431ad0c6a099a4b8b52.md b/curriculum/challenges/english/blocks/lab-all-true-property-validator/a10d2431ad0c6a099a4b8b52.md new file mode 100644 index 00000000000..f4e6eb196b8 --- /dev/null +++ b/curriculum/challenges/english/blocks/lab-all-true-property-validator/a10d2431ad0c6a099a4b8b52.md @@ -0,0 +1,181 @@ +--- +id: a10d2431ad0c6a099a4b8b52 +title: Build an All-True Property Validator +challengeType: 26 +dashedName: build-an-all-true-property-validator +--- + +# --description-- + +In this lab you will test a specific property of each object in an array to see if it always has a truthy value or not. + +For example, you could be asked to test one property of the objects in an array like the following: + +```js +[{ + name: "Quincy", + role: "Founder", + isBot: false +}, { + name: "Naomi", + role: "", + isBot: false +}, { + name: "Camperbot", + role: "Bot", + isBot: true +}] +``` + +If you were asked to test the `name` property, in the objects of this array the property `name` has the values of `"Quincy"`, `"Naomi"`, and `"Camperbot"`, so it is always truthy. + +If you were asked to test the `role` property, the values are `"Founder"`, `""`, and `"Bot"`, in this case `""` is a falsy value, so the values are not always truthy. + +**Objective:** Fulfill the user stories below and get all the tests to pass to complete the lab. + +**User Stories:** + +1. You should have a function named `truthCheck`. +1. The `truthCheck` function takes two arguments: an array of objects and a string representing a property name found in those objects. +1. The function should check if the property with the name equal to the second argument has a truthy value in all the objects of the array, and return `true` if it has, and `false` otherwise. + +# --hints-- + +`truthCheck([{name: "Quincy", role: "Founder", isBot: false}, {name: "Naomi", role: "", isBot: false}, {name: "Camperbot", role: "Bot", isBot: true}], "isBot")` should return `false`. + +```js +assert.strictEqual(truthCheck( + [ + { name: "Quincy", role: "Founder", isBot: false }, + { name: "Naomi", role: "", isBot: false }, + { name: "Camperbot", role: "Bot", isBot: true } + ], + "isBot"), false); +``` + +`truthCheck([{name: "Quincy", role: "Founder", isBot: false}, {name: "Naomi", role: "", isBot: false}, {name: "Camperbot", role: "Bot", isBot: true}], "name")` should return `true`. + +```js +assert.strictEqual(truthCheck( + [ + { name: "Quincy", role: "Founder", isBot: false }, + { name: "Naomi", role: "", isBot: false }, + { name: "Camperbot", role: "Bot", isBot: true } + ], + "name"), true); +``` + +`truthCheck([{name: "Quincy", role: "Founder", isBot: false}, {name: "Naomi", role: "", isBot: false}, {name: "Camperbot", role: "Bot", isBot: true}], "role")` should return `false`. + +```js +assert.strictEqual(truthCheck( + [ + { name: "Quincy", role: "Founder", isBot: false }, + { name: "Naomi", role: "", isBot: false }, + { name: "Camperbot", role: "Bot", isBot: true } + ], + "role"), false); +``` + +`truthCheck([{name: "Pikachu", number: 25, caught: 3}, {name: "Togepi", number: 175, caught: 1}], "number")` should return `true`. + +```js +assert.strictEqual(truthCheck( + [ + { name: "Pikachu", number: 25, caught: 3 }, + { name: "Togepi", number: 175, caught: 1 }, + ], + "number"), true); +``` + +`truthCheck([{name: "Pikachu", number: 25, caught: 3}, {name: "Togepi", number: 175, caught: 1}, {name: "MissingNo", number: NaN, caught: 0}], "caught")` should return `false`. + +```js +assert.strictEqual(truthCheck( + [ + { name: "Pikachu", number: 25, caught: 3 }, + { name: "Togepi", number: 175, caught: 1 }, + { name: "MissingNo", number: NaN, caught: 0 }, + ], + "caught"), false); +``` + +`truthCheck([{name: "Pikachu", number: 25, caught: 3}, {name: "Togepi", number: 175, caught: 1}, {name: "MissingNo", number: NaN, caught: 0}], "number")` should return `false`. + +```js +assert.strictEqual(truthCheck( + [ + { name: "Pikachu", number: 25, caught: 3 }, + { name: "Togepi", number: 175, caught: 1 }, + { name: "MissingNo", number: NaN, caught: 0 }, + ], + "number"), false); +``` + +`truthCheck([{name: "Quincy", username: "QuincyLarson"}, {name: "Naomi", username: "nhcarrigan"}, {name: "Camperbot"}], "username")` should return `false`. + +```js +assert.strictEqual(truthCheck( + [ + { name: "Quincy", username: "QuincyLarson" }, + { name: "Naomi", username: "nhcarrigan" }, + { name: "Camperbot" } + ], + "username"), false); +``` + +`truthCheck([{name: "freeCodeCamp", users: [{name: "Quincy"}, {name: "Naomi"}]}, {name: "Code Radio", users: [{name: "Camperbot"}]}, {name: "", users: []}], "users")` should return `true`. + +```js +assert.strictEqual(truthCheck( + [ + { name: "freeCodeCamp", users: [{ name: "Quincy" }, { name: "Naomi" }] }, + { name: "Code Radio", users: [{ name: "Camperbot" }] }, + { name: "", users: [] }, + ], + "users"), true); +``` + +`truthCheck([{id: 1, data: {url: "https://freecodecamp.org", name: "freeCodeCamp"}}, {id: 2, data: {url: "https://coderadio.freecodecamp.org/", name: "CodeRadio"}}, {id: null, data: {}}], "data")` should return `true`. + +```js +assert.strictEqual(truthCheck( + [ + { id: 1, data: { url: "https://freecodecamp.org", name: "freeCodeCamp" } }, + { id: 2, data: { url: "https://coderadio.freecodecamp.org/", name: "CodeRadio" } }, + { id: null, data: {} }, + ], + "data"), true); +``` + +`truthCheck([{id: 1, data: {url: "https://freecodecamp.org", name: "freeCodeCamp"}}, {id: 2, data: {url: "https://coderadio.freecodecamp.org/", name: "CodeRadio"}}, {id: null, data: {}}], "id")` should return `false`. + +```js +assert.strictEqual(truthCheck( + [ + { id: 1, data: { url: "https://freecodecamp.org", name: "freeCodeCamp" } }, + { id: 2, data: { url: "https://coderadio.freecodecamp.org/", name: "CodeRadio" } }, + { id: null, data: {} }, + ], + "id"), false); +``` + +# --seed-- + +## --seed-contents-- + +```js +function truthCheck(collection, pre) { + return pre; +} + +truthCheck([{name: "Quincy", role: "Founder", isBot: false}, {name: "Naomi", role: "", isBot: false}, {name: "Camperbot", role: "Bot", isBot: true}], "isBot"); +``` + +# --solutions-- + +```js +function truthCheck(collection, pre) { + return collection.every(function(e) { return e[pre]; }); +} +``` diff --git a/curriculum/structure/blocks/lab-all-true-property-validator.json b/curriculum/structure/blocks/lab-all-true-property-validator.json new file mode 100644 index 00000000000..a85d4533908 --- /dev/null +++ b/curriculum/structure/blocks/lab-all-true-property-validator.json @@ -0,0 +1,15 @@ +{ + "name": "Build an All-True Property Validator", + "blockType": "lab", + "blockLayout": "link", + "isUpcomingChange": false, + "usesMultifileEditor": true, + "dashedName": "lab-all-true-property-validator", + "challengeOrder": [ + { + "id": "a10d2431ad0c6a099a4b8b52", + "title": "Build an All-True Property Validator" + } + ], + "helpCategory": "JavaScript" +} diff --git a/curriculum/structure/superblocks/full-stack-developer.json b/curriculum/structure/superblocks/full-stack-developer.json index 37f3b6ef90d..8cac55cdaf3 100644 --- a/curriculum/structure/superblocks/full-stack-developer.json +++ b/curriculum/structure/superblocks/full-stack-developer.json @@ -410,6 +410,7 @@ "lab-matching-object-filter", "lab-sum-all-primes-calculator", "lab-deep-flattening-tool", + "lab-all-true-property-validator", "review-javascript-higher-order-functions", "quiz-javascript-higher-order-functions" ]