From 24f294c462b04ce8e6a57b3e9875f7d1efca5f9b Mon Sep 17 00:00:00 2001 From: Alaa Tagi Date: Mon, 13 Oct 2025 20:30:45 +0100 Subject: [PATCH 01/11] write js card-validator code with explanation of some lines and some test cases --- Sprint-3/3-stretch/card-validator.md | 35 ---------------------------- 1 file changed, 35 deletions(-) delete mode 100644 Sprint-3/3-stretch/card-validator.md diff --git a/Sprint-3/3-stretch/card-validator.md b/Sprint-3/3-stretch/card-validator.md deleted file mode 100644 index e39c6ace6..000000000 --- a/Sprint-3/3-stretch/card-validator.md +++ /dev/null @@ -1,35 +0,0 @@ -## **PROJECT: Credit Card Validator** - -In this project you'll write a script that validates whether or not a credit card number is valid. - -Here are the rules for a valid number: - -- Number must be 16 digits, all of them must be numbers. -- You must have at least two different digits represented (all of the digits cannot be the same). -- The final digit must be even. -- The sum of all the digits must be greater than 16. - -For example, the following credit card numbers are valid: - -```markdown -9999777788880000 -6666666666661666 -``` - -And the following credit card numbers are invalid: - -```markdown -a92332119c011112 (invalid characters) -4444444444444444 (only one type of number) -1111111111111110 (sum less than 16) -6666666666666661 (odd final number) -``` - -These are the requirements your project needs to fulfill: - -- Make a JavaScript file with a name that describes its contents. -- Create a function with a descriptive name which makes it clear what the function does. The function should take one argument, the credit card number to validate. -- Write at least 2 comments that explain to others what a line of code is meant to do. -- Return a boolean from the function to indicate whether the credit card number is valid. - -Good luck! From 6b8d975803927530beea4cd7c426b63f91305e21 Mon Sep 17 00:00:00 2001 From: Alaa Tagi Date: Mon, 13 Oct 2025 20:36:29 +0100 Subject: [PATCH 02/11] answer the questions in the code --- Sprint-3/3-stretch/find.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Sprint-3/3-stretch/find.js b/Sprint-3/3-stretch/find.js index c7e79a2f2..a80a1ea19 100644 --- a/Sprint-3/3-stretch/find.js +++ b/Sprint-3/3-stretch/find.js @@ -20,6 +20,10 @@ console.log(find("code your future", "z")); // Pay particular attention to the following: // a) How the index variable updates during the call to find +// In the beginning of the function it is set to 0, then each time the while loop runs it increases by 1 until it reaches the length of the string . // b) What is the if statement used to check +// The if statement checks if the character at the current index of the string is equal to the character we are searching for. If it is, the function returns the current index. // c) Why is index++ being used? +// The index++ is used to move to the next character in the string after each iteration of the while loop. // d) What is the condition index < str.length used for? +// The condition index < str.length is used to ensure that the while loop continues to run as long as there are characters left to check in the string. From 8499ca3aabbe5b0baad48339ddcf0e7ec1079107 Mon Sep 17 00:00:00 2001 From: Alaa Tagi Date: Mon, 13 Oct 2025 20:44:47 +0100 Subject: [PATCH 03/11] Editing passwordValidator code --- Sprint-3/3-stretch/password-validator.js | 30 +++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/Sprint-3/3-stretch/password-validator.js b/Sprint-3/3-stretch/password-validator.js index b55d527db..64d38501f 100644 --- a/Sprint-3/3-stretch/password-validator.js +++ b/Sprint-3/3-stretch/password-validator.js @@ -1,6 +1,30 @@ -function passwordValidator(password) { - return password.length < 5 ? false : true -} +const passwords = ["Amtf22#", "123$cdo"]; +function passwordValidator(password) { + if (password.length < 5) { + return false; + } + + if (!/[A-Z]/.test(password)) { + return false; + } + + if (!/[a-z]/.test(password)) { + return false; + } + + if (!/[0-9]/.test(password)) { + return false; + } + if (!/[!#$%&? "]/.test(password)) { + return false; + } + if (passwords.includes(password)) { + return false; + } + + + return true; +} module.exports = passwordValidator; \ No newline at end of file From 14ab0f67ac315e1fdd8ef223174322b96884bdba Mon Sep 17 00:00:00 2001 From: Alaa Tagi Date: Mon, 13 Oct 2025 20:52:51 +0100 Subject: [PATCH 04/11] rewrite test with jest for password-validator --- Sprint-3/3-stretch/password-validator.test.js | 50 ++++++++++++++++++- 1 file changed, 48 insertions(+), 2 deletions(-) diff --git a/Sprint-3/3-stretch/password-validator.test.js b/Sprint-3/3-stretch/password-validator.test.js index 8fa3089d6..4ec06543b 100644 --- a/Sprint-3/3-stretch/password-validator.test.js +++ b/Sprint-3/3-stretch/password-validator.test.js @@ -21,6 +21,52 @@ test("password has at least 5 characters", () => { // Act const result = isValidPassword(password); // Assert - expect(result).toEqual(true); + expect(result).toEqual(false); } -); \ No newline at end of file +); + +// passsword has at least one uppercase letter +test("password has at least one uppercase letter", () => { + + const password = "1234a"; + const result = isValidPassword(password); + expect(result).toEqual(false); +} +); + +// password has at least one lowercase letter +test("password has at least one lowercase letter", () => { + + const password = "1234A"; + const result = isValidPassword(password); + expect(result).toEqual(false); +} +); + +// password has at least one number +test("password has at least one number", () => { + + const password = "abcdA"; + const result = isValidPassword(password); + expect(result).toEqual(false); +} +); + +// password has at least one symbol: +test("password has at least one symbol: (!, #, $, %, ., *, &)", () => { + + const password = "abcdA1"; + const result = isValidPassword(password); + expect(result).toEqual(false); +} +); + +// password must not be any previous password in the passwords array. +test("password must not be any previous password in the passwords array.", () => { + + const password = "Amtf22#"; + const result = isValidPassword(password); + expect(result).toEqual(false); +} +); + From e2191a40217467edc3c3ac03a98de21076e1dcac Mon Sep 17 00:00:00 2001 From: Alaa Tagi Date: Mon, 13 Oct 2025 21:01:12 +0100 Subject: [PATCH 05/11] fix the code --- Sprint-3/3-stretch/password-validator.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-3/3-stretch/password-validator.test.js b/Sprint-3/3-stretch/password-validator.test.js index 4ec06543b..e910a9d2c 100644 --- a/Sprint-3/3-stretch/password-validator.test.js +++ b/Sprint-3/3-stretch/password-validator.test.js @@ -64,7 +64,7 @@ test("password has at least one symbol: (!, #, $, %, ., *, &)", () => { // password must not be any previous password in the passwords array. test("password must not be any previous password in the passwords array.", () => { - const password = "Amtf22#"; + const password = "Aq@1122#"; const result = isValidPassword(password); expect(result).toEqual(false); } From 7f09ec55632c7f525b44b9097438cf2d08b1429c Mon Sep 17 00:00:00 2001 From: Alaa Tagi Date: Mon, 13 Oct 2025 21:02:07 +0100 Subject: [PATCH 06/11] fix the code --- Sprint-3/3-stretch/password-validator.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-3/3-stretch/password-validator.js b/Sprint-3/3-stretch/password-validator.js index 64d38501f..fa2700ddd 100644 --- a/Sprint-3/3-stretch/password-validator.js +++ b/Sprint-3/3-stretch/password-validator.js @@ -1,4 +1,4 @@ -const passwords = ["Amtf22#", "123$cdo"]; +const passwords = ["Aq@1122#", "123$cdo"]; function passwordValidator(password) { if (password.length < 5) { return false; From 46024deb180ad7589ecc1c2a5d30e508c7d89688 Mon Sep 17 00:00:00 2001 From: Alaa Tagi Date: Mon, 13 Oct 2025 21:15:31 +0100 Subject: [PATCH 07/11] fix the code --- Sprint-3/3-stretch/password-validator.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-3/3-stretch/password-validator.js b/Sprint-3/3-stretch/password-validator.js index fa2700ddd..93cded8d0 100644 --- a/Sprint-3/3-stretch/password-validator.js +++ b/Sprint-3/3-stretch/password-validator.js @@ -1,4 +1,4 @@ -const passwords = ["Aq@1122#", "123$cdo"]; +const passwords = ["aebdc!", "123$cdo"]; function passwordValidator(password) { if (password.length < 5) { return false; From 444fbb977bd900a06a6726fc57278ef7555f4575 Mon Sep 17 00:00:00 2001 From: Alaa Tagi Date: Mon, 13 Oct 2025 21:23:48 +0100 Subject: [PATCH 08/11] fix the code --- Sprint-3/3-stretch/password-validator.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-3/3-stretch/password-validator.js b/Sprint-3/3-stretch/password-validator.js index 93cded8d0..fa1596eac 100644 --- a/Sprint-3/3-stretch/password-validator.js +++ b/Sprint-3/3-stretch/password-validator.js @@ -1,4 +1,4 @@ -const passwords = ["aebdc!", "123$cdo"]; +const passwords = ["Abcde1!", "Hello#2"]; function passwordValidator(password) { if (password.length < 5) { return false; From df9863b64bce8258d93751589dc86f5eae6a1825 Mon Sep 17 00:00:00 2001 From: Alaa Tagi Date: Mon, 13 Oct 2025 21:24:26 +0100 Subject: [PATCH 09/11] fix the code --- Sprint-3/3-stretch/password-validator.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-3/3-stretch/password-validator.test.js b/Sprint-3/3-stretch/password-validator.test.js index e910a9d2c..f42462b99 100644 --- a/Sprint-3/3-stretch/password-validator.test.js +++ b/Sprint-3/3-stretch/password-validator.test.js @@ -64,7 +64,7 @@ test("password has at least one symbol: (!, #, $, %, ., *, &)", () => { // password must not be any previous password in the passwords array. test("password must not be any previous password in the passwords array.", () => { - const password = "Aq@1122#"; + const password = "abcde1!"; const result = isValidPassword(password); expect(result).toEqual(false); } From 9354edf25d22a78fe58333d69c1051d49d835b95 Mon Sep 17 00:00:00 2001 From: Alaa-Tagi Date: Mon, 27 Oct 2025 18:07:13 +0000 Subject: [PATCH 10/11] fixing code to meet all requirements --- Sprint-3/3-stretch/password-validator.test.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/Sprint-3/3-stretch/password-validator.test.js b/Sprint-3/3-stretch/password-validator.test.js index f42462b99..54ac053c9 100644 --- a/Sprint-3/3-stretch/password-validator.test.js +++ b/Sprint-3/3-stretch/password-validator.test.js @@ -28,7 +28,7 @@ test("password has at least 5 characters", () => { // passsword has at least one uppercase letter test("password has at least one uppercase letter", () => { - const password = "1234a"; + const password = "abcd!1"; const result = isValidPassword(password); expect(result).toEqual(false); } @@ -37,7 +37,7 @@ test("password has at least one uppercase letter", () => { // password has at least one lowercase letter test("password has at least one lowercase letter", () => { - const password = "1234A"; + const password = "ABCD!1"; const result = isValidPassword(password); expect(result).toEqual(false); } @@ -46,7 +46,7 @@ test("password has at least one lowercase letter", () => { // password has at least one number test("password has at least one number", () => { - const password = "abcdA"; + const password = "Abcd!@"; const result = isValidPassword(password); expect(result).toEqual(false); } @@ -55,7 +55,7 @@ test("password has at least one number", () => { // password has at least one symbol: test("password has at least one symbol: (!, #, $, %, ., *, &)", () => { - const password = "abcdA1"; + const password = "abcd12"; const result = isValidPassword(password); expect(result).toEqual(false); } @@ -64,9 +64,16 @@ test("password has at least one symbol: (!, #, $, %, ., *, &)", () => { // password must not be any previous password in the passwords array. test("password must not be any previous password in the passwords array.", () => { - const password = "abcde1!"; + const password = "abcd!1"; const result = isValidPassword(password); expect(result).toEqual(false); } ); - +// password is valid when all requirements are met +test ("password is valid when it meets all requirements",()d=>{ + + const passsword = "Abcd!2"; + const result = isValidPassword(passsword); + expect(result).toEqual(true); +} +); From d50290ef25f027aaa3d8d96c003f0018ad6a6e3f Mon Sep 17 00:00:00 2001 From: Alaa-Tagi Date: Mon, 27 Oct 2025 18:27:46 +0000 Subject: [PATCH 11/11] editing the code --- Sprint-3/3-stretch/password-validator.test.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sprint-3/3-stretch/password-validator.test.js b/Sprint-3/3-stretch/password-validator.test.js index 54ac053c9..023b30222 100644 --- a/Sprint-3/3-stretch/password-validator.test.js +++ b/Sprint-3/3-stretch/password-validator.test.js @@ -70,10 +70,10 @@ test("password must not be any previous password in the passwords array.", () => } ); // password is valid when all requirements are met -test ("password is valid when it meets all requirements",()d=>{ +test ("password is valid when it meets all requirements",() =>{ - const passsword = "Abcd!2"; - const result = isValidPassword(passsword); + const password = "Abcd!2"; + const result = isValidPassword(password); expect(result).toEqual(true); } );