Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Home Work 2 done #1

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions session-01/basics.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -162,3 +170,4 @@ while (j < schoolName.length) {
console.log(schoolName[j]);
j++;
}
>>>>>>> origin/week-2
25 changes: 23 additions & 2 deletions session-01/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/*
Expand All @@ -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;
Comment on lines +28 to +41
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is correct, but for clarity in more complex code, consider using if-statement guard clauses like in this example: https://github.com/CUNYTechPrep/js-summer-prep-2024/blob/main/session-01/validators.solution.js#L10-L16

}

module.exports = { validUsername, validPassword };
14 changes: 12 additions & 2 deletions session-02/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/*
Expand All @@ -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 };