diff --git a/client/i18n/locales/english/intro.json b/client/i18n/locales/english/intro.json index 5a0bf95c6da..415d8b2b2a1 100644 --- a/client/i18n/locales/english/intro.json +++ b/client/i18n/locales/english/intro.json @@ -2838,7 +2838,10 @@ "In these lecture videos, you will learn about modules, imports, and exports in JavaScript." ] }, - "lnmg": { "title": "179", "intro": [] }, + "lab-password-generator": { + "title": "Build a Password Generator App", + "intro": ["In this lab, you'll build a password generator app."] + }, "review-javascript-fundamentals": { "title": "JavaScript Fundamentals Review", "intro": [ diff --git a/client/src/pages/learn/full-stack-developer/lab-password-generator/index.md b/client/src/pages/learn/full-stack-developer/lab-password-generator/index.md new file mode 100644 index 00000000000..b41bf87c061 --- /dev/null +++ b/client/src/pages/learn/full-stack-developer/lab-password-generator/index.md @@ -0,0 +1,9 @@ +--- +title: Introduction to the Build a Password Generator App +block: lab-password-generator +superBlock: full-stack-developer +--- + +## Introduction to the Build a Password Generator App + +In this lab, you'll build a password generator app. diff --git a/curriculum/challenges/_meta/lab-password-generator/meta.json b/curriculum/challenges/_meta/lab-password-generator/meta.json new file mode 100644 index 00000000000..f49408288da --- /dev/null +++ b/curriculum/challenges/_meta/lab-password-generator/meta.json @@ -0,0 +1,11 @@ +{ + "name": "Build a Password Generator App", + "isUpcomingChange": true, + "usesMultifileEditor": true, + "blockType": "lab", + "dashedName": "lab-password-generator", + "superBlock": "full-stack-developer", + "challengeOrder": [{ "id": "66f53dc2c5bd6a11d6c3282f", "title": "Build a Password Generator App" }], + "helpCategory": "JavaScript", + "blockLayout": "link" +} diff --git a/curriculum/challenges/english/25-front-end-development/lab-password-generator/66f53dc2c5bd6a11d6c3282f.md b/curriculum/challenges/english/25-front-end-development/lab-password-generator/66f53dc2c5bd6a11d6c3282f.md new file mode 100644 index 00000000000..4e476e95f4a --- /dev/null +++ b/curriculum/challenges/english/25-front-end-development/lab-password-generator/66f53dc2c5bd6a11d6c3282f.md @@ -0,0 +1,116 @@ +--- +id: 66f53dc2c5bd6a11d6c3282f +title: Build a Password Generator App +challengeType: 25 +dashedName: lab-password-generator +--- + +# --description-- + +In this lab, you'll practice using functions by building a random password generator. + +**Objective:** Fulfill the user stories below and get all the tests to pass to complete the lab. + +**User Stories:** + +1. You should create a function called `generatePassword` that takes a parameter. You can name the parameter whatever you like. +2. Your function should return a string which represents a randomly generated password. You should use the following string and different `Math` methods to help you return a new string with random characters in it: `ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()`. +3. You should define a variable called `password` and assign it the result of calling the `generatePassword` function with a numeric argument that represents the desired password length. +4. You should have a `console.log` that logs the message `"Generated password:"` followed by the `password` variable. + +# --hints-- + +You should have a `generatePassword` function with a parameter. You can name the parameter whatever you like. + +```js +assert.isFunction(generatePassword); +assert.lengthOf(generatePassword, 1); +``` + +Your `generatePassword` function should return a string. + +```js +const result = generatePassword(5); +assert.isString(result); +``` + +Your `generatePassword` function should return a new string that is the correct length. + +```js +const length = 8; +const password = generatePassword(length); +assert.lengthOf(password, length); +``` + +Your function should return a randomly generated password with valid characters. + +```js +const validChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()"; +const password = generatePassword(10); +for (let char of password) { + assert.include(validChars, char); +} +``` + +Your function should return a new random string each time it is called. + +```js +const password1 = generatePassword(10); +const password2 = generatePassword(10); +assert.notStrictEqual(password1, password2); +``` + +You should have a `password` variable. + +```js +assert.isDefined(password); +``` + +Your `password` variable should be a string. + +```js +assert.isString(password); +``` + +You should call the `generatePassword` function with a numeric argument and store the returned password in the `password` variable. + +```js +assert.isDefined(password); +assert.isString(password); +const testLength = password.length; +assert.strictEqual(password.length, testLength); +assert.match(password, /^[A-Za-z0-9!@#$%^&*()]+$/); +``` + +You should log the generated password to the console. + +```js +const condition1 = /console\.log\(\s*["']Generated\s+password:\s*["']\s*\+\s*password\s*\);?/gm.test(code); +const condition2 = /console\.log\(\s*`Generated\s+password:\s*\$\{password\}`\s*\);?/gm.test(code); +assert.isTrue(condition1 || condition2); +``` + +# --seed-- + +## --seed-contents-- + +```js + +``` + +# --solutions-- + +```js +const generatePassword = (length) => { + const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()"; + let password = ""; + for (let i = 0; i < length; i++) { + const randomIndex = Math.floor(Math.random() * chars.length); + password += chars[randomIndex]; + } + return password; +}; + +const password = generatePassword(12); +console.log(`Generated password: ${password}`); +``` diff --git a/curriculum/superblock-structure/full-stack.json b/curriculum/superblock-structure/full-stack.json index c35301206d4..2b03927366b 100644 --- a/curriculum/superblock-structure/full-stack.json +++ b/curriculum/superblock-structure/full-stack.json @@ -376,6 +376,7 @@ { "dashedName": "lecture-understanding-modules-imports-and-exports" }, + { "dashedName": "lab-password-generator" }, { "dashedName": "review-javascript-fundamentals" }, { "dashedName": "quiz-javascript-fundamentals" } ]