From bb1c582d798ce6759bb4f077e998238beb10c91d Mon Sep 17 00:00:00 2001 From: ravimultani38 Date: Wed, 7 Aug 2024 09:48:07 -0400 Subject: [PATCH 1/3] Session-01 assignment completed --- session-01/validators.js | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/session-01/validators.js b/session-01/validators.js index 56ea66d..cae4ea7 100644 --- a/session-01/validators.js +++ b/session-01/validators.js @@ -7,7 +7,22 @@ - username cannot contain special characters */ function validUsername(username) { - return; + // Check length + if (username.length < 3 || username.length > 10) { + return false; + } + + // Check if it begins with a letter + if (!/^[a-zA-Z]/.test(username)) { + return false; + } + + // Check if it only contains letters and numbers + if (!/^[a-zA-Z0-9]+$/.test(username)) { + return false; + } + + return true; } /* @@ -17,7 +32,21 @@ function validUsername(username) { - password must contain at least 1 letter, 1 number, and 1 special character */ function validPassword(password) { - return; + // Check length + if (password.length < 10 || password.length > 64) { + return false; + } + + // Check for at least 1 letter, 1 number, and 1 special character + const hasLetter = /[a-zA-Z]/.test(password); + const hasNumber = /[0-9]/.test(password); + const hasSpecialChar = /[!@#$%^&*(),.?":{}|<>]/.test(password); + + if (!hasLetter || !hasNumber || !hasSpecialChar) { + return false; + } + + return true; } module.exports = { validUsername, validPassword }; From 3f2c81ac005518844f0305d00a4e231bd22ae178 Mon Sep 17 00:00:00 2001 From: ravimultani38 Date: Wed, 14 Aug 2024 13:35:04 -0400 Subject: [PATCH 2/3] session-2 completed --- session-02/exercise.js | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/session-02/exercise.js b/session-02/exercise.js index 6ade818..61d0e3b 100644 --- a/session-02/exercise.js +++ b/session-02/exercise.js @@ -1,22 +1,25 @@ -/* - Transform the input array of strings into uppercase strings - For example, for the input ["cat", "hat"], return ["CAT", "HAT"] -*/ +/** + * Transform the input array of strings into uppercase strings. + * @param {string[]} listOfStrings - An array of strings to transform. + * @returns {string[]} An array of strings in uppercase. + */ function transformArrayToUpper(listOfStrings) { - return; + return listOfStrings.map(string => string.toUpperCase()); } -/* - Write a function that returns the sum of all student ages. - The function will be passed an array of objects and the result - will be the sum of all ages. - - Note, not all objects will contain an age. Omit these objects. - For example, for the input: - [{ name: 'Sandra', age: 31 }, {}, { name: 'Didi', age: 20}] - the function should return 51 -*/ +/** + * Write a function that returns the sum of all student ages. + * The function will be passed an array of objects, and the result + * will be the sum of all ages. + * Note, not all objects will contain an age. Omit these objects. + * @param {Object[]} listOfStudentObjects - Array of student objects. + * @returns {number} The sum of ages of students with an 'age' property. + */ function sumOfAllAges(listOfStudentObjects) { - return; + return listOfStudentObjects + .filter(student => student.age !== undefined) // Filter objects that have an age property + .reduce((sum, student) => sum + student.age, 0); // Sum up the ages } module.exports = { transformArrayToUpper, sumOfAllAges }; + From 36baf51bbdf4467ce31935fec2076c6d59358534 Mon Sep 17 00:00:00 2001 From: ravimultani38 Date: Wed, 21 Aug 2024 12:13:11 -0400 Subject: [PATCH 3/3] Session-3 completed --- session-03/js-patterns.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/session-03/js-patterns.js b/session-03/js-patterns.js index 5291252..21bdbe3 100644 --- a/session-03/js-patterns.js +++ b/session-03/js-patterns.js @@ -23,6 +23,9 @@ let driverAge = 16; // try changing to 16 or greater driverAge >= 16 && console.log("this person can drive"); // Ternary operator: ( ? : ) +let luckyNumber = 8; // Define luckyNumber +let guess = 8; // Define guess + let result = luckyNumber === guess ? "right" : "wrong"; // let result = "";