diff --git a/session-01/basics.js b/session-01/basics.js index e58b018..b023a33 100644 --- a/session-01/basics.js +++ b/session-01/basics.js @@ -7,6 +7,14 @@ is a multi line comment */ +<<<<<<< HEAD +//console.log("Hello World") + +let age = 15; +console.log("My age is",age) +agqw = "twantiy" +console.log(agqw.charAt(0)) +======= /***** Printing output *****/ // for debug/info purposes console.log("Hello CTP class"); @@ -162,3 +170,4 @@ while (j < schoolName.length) { console.log(schoolName[j]); j++; } +>>>>>>> origin/week-2 diff --git a/session-01/validators.js b/session-01/validators.js index 56ea66d..c9a39ab 100644 --- a/session-01/validators.js +++ b/session-01/validators.js @@ -7,7 +7,15 @@ - username cannot contain special characters */ function validUsername(username) { - return; + let SpecialChars = /[!@#$%^&*.?]/; + if(username.length>2 && username.length <11){ + if(username.charAt(0).toUpperCase() != username.charAt(0).toLowerCase()){ + if(username.search(SpecialChars)== -1){ + return true; + } + } + } + return false; } /* @@ -17,7 +25,20 @@ function validUsername(username) { - password must contain at least 1 letter, 1 number, and 1 special character */ function validPassword(password) { - return; + let SpecialChars = /[!@#$%^&*.?]/; + let UpperLetter = /[a-z]/; + let LowerLetter = /[A-Z]/; + let Num = /[0-9]/; + if(password.length>9&&password.length<65){ + if(password.search(SpecialChars)!=-1){ + if(password.search(UpperLetter)!=-1 || password.search(LowerLetter)!=-1){ + if(password.search(Num)!=-1){ + return true; + } + } + } + } + return false; } module.exports = { validUsername, validPassword }; diff --git a/session-02/exercise.js b/session-02/exercise.js index 6ade818..187b2ac 100644 --- a/session-02/exercise.js +++ b/session-02/exercise.js @@ -3,7 +3,11 @@ For example, for the input ["cat", "hat"], return ["CAT", "HAT"] */ function transformArrayToUpper(listOfStrings) { - return; + let UpperString = []; + for(const word of listOfStrings){ + UpperString.push(word.toUpperCase()); + } + return UpperString; } /* @@ -16,7 +20,13 @@ function transformArrayToUpper(listOfStrings) { the function should return 51 */ function sumOfAllAges(listOfStudentObjects) { - return; + let totalAge = 0; + for(const student of listOfStudentObjects){ + if(student.age){ + totalAge += student.age; + } + } + return totalAge; } module.exports = { transformArrayToUpper, sumOfAllAges };