From 38df360d472be5492923362f15835b03e72103e5 Mon Sep 17 00:00:00 2001 From: SiyaM108 Date: Sat, 9 Aug 2025 14:47:05 +0100 Subject: [PATCH 01/10] done --- js/index.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/js/index.js b/js/index.js index 59e4af7..0fbe325 100644 --- a/js/index.js +++ b/js/index.js @@ -1,3 +1,5 @@ +console.log("I'm ready!"); + // Iteration 1: Names and Input // // Iteration 2: Conditionals From 801287ac20082910b1f30c816658ba4dd448334a Mon Sep 17 00:00:00 2001 From: SiyaM108 Date: Sat, 9 Aug 2025 14:56:22 +0100 Subject: [PATCH 02/10] create variable hacker1 --- js/index.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/js/index.js b/js/index.js index 0fbe325..fd3605c 100644 --- a/js/index.js +++ b/js/index.js @@ -1,7 +1,10 @@ console.log("I'm ready!"); // Iteration 1: Names and Input -// +let hacker1 = "Alice"; +console.log(`The driver's name is ${hacker1}`); + + // Iteration 2: Conditionals From 1aa1659519a652e2497fba2e99f178c5829194ae Mon Sep 17 00:00:00 2001 From: SiyaM108 Date: Sat, 9 Aug 2025 14:58:06 +0100 Subject: [PATCH 03/10] create variable hacker2 --- js/index.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/js/index.js b/js/index.js index fd3605c..3403b15 100644 --- a/js/index.js +++ b/js/index.js @@ -4,6 +4,8 @@ console.log("I'm ready!"); let hacker1 = "Alice"; console.log(`The driver's name is ${hacker1}`); +let hacker2 = "Bob"; +console.log(`The navigator's name is ${hacker2}`); // Iteration 2: Conditionals From 3a99049d85390c5b8529a95e4e7f4ad17bf96e85 Mon Sep 17 00:00:00 2001 From: SiyaM108 Date: Sat, 9 Aug 2025 15:02:57 +0100 Subject: [PATCH 04/10] compare variable lengths --- js/index.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/js/index.js b/js/index.js index 3403b15..48b3aff 100644 --- a/js/index.js +++ b/js/index.js @@ -8,6 +8,12 @@ let hacker2 = "Bob"; console.log(`The navigator's name is ${hacker2}`); // Iteration 2: Conditionals - +if(hacker1.length > hacker2.length) { + console.log(`The driver has the longest name, it has ${hacker1.length} characters.`); +} else if(hacker1.length < hacker2.length) { + console.log(`It seems that the navigator has the longest name, it has ${hacker2.length} characters.`); +} else { + console.log(`Wow, you both have equally long names, ${hacker1.length} characters!`); +} // Iteration 3: Loops From f52b6c9ed87c1e7059f030b51e1e76717eb20578 Mon Sep 17 00:00:00 2001 From: SiyaM108 Date: Sat, 9 Aug 2025 15:11:16 +0100 Subject: [PATCH 05/10] uppercase and reverse varables --- js/index.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/js/index.js b/js/index.js index 48b3aff..2f29c1a 100644 --- a/js/index.js +++ b/js/index.js @@ -17,3 +17,14 @@ if(hacker1.length > hacker2.length) { } // Iteration 3: Loops +let upperCaseName = ""; +for (let i = 0; i < hacker1.length; i++) { + upperCaseName += hacker1[i].toUpperCase() + " "; +} +console.log(upperCaseName); + +let reversedName = ""; +for (let i = hacker2.length - 1; i >= 0; i--) { + reversedName += hacker2[i]; +} +console.log(reversedName); From c822b1768ee68e247ee8573a9443c0bfc940793c Mon Sep 17 00:00:00 2001 From: SiyaM108 Date: Sat, 9 Aug 2025 15:14:17 +0100 Subject: [PATCH 06/10] compare lexicographic order --- js/index.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/js/index.js b/js/index.js index 2f29c1a..82f4719 100644 --- a/js/index.js +++ b/js/index.js @@ -28,3 +28,14 @@ for (let i = hacker2.length - 1; i >= 0; i--) { reversedName += hacker2[i]; } console.log(reversedName); + +// Lexicographic Order +if (hacker1.localeCompare(hacker2) < 0) { + console.log(`The driver's name goes first.`); +} +else if (hacker1.localeCompare(hacker2) > 0) { + console.log(`Yo, the navigator goes first definitely.`); +} +else { + console.log(`What?! You both have the same name?`); +} From 0150cde4143ff93967af2d559bcd833b7b338643 Mon Sep 17 00:00:00 2001 From: SiyaM108 Date: Sat, 9 Aug 2025 15:43:51 +0100 Subject: [PATCH 07/10] count words from lorem paragraphs --- js/index.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/js/index.js b/js/index.js index 82f4719..60f9881 100644 --- a/js/index.js +++ b/js/index.js @@ -39,3 +39,8 @@ else if (hacker1.localeCompare(hacker2) > 0) { else { console.log(`What?! You both have the same name?`); } + +// Bonus 1: Count the words +let myParagraph = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.\n\nSed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?\n\nAt vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Temporibus autem quibusdam et aut officiis debitis aut rerum necessitatibus saepe eveniet ut et voluptates repudiandae sint et molestiae non recusandae. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat."; +let wordCount = myParagraph.split(" ").length; +console.log(`Word count: ${wordCount}`); From 95176ba19aa8e65831e791fe8c87788d610451f3 Mon Sep 17 00:00:00 2001 From: SiyaM108 Date: Sat, 9 Aug 2025 15:47:37 +0100 Subject: [PATCH 08/10] count the occurence of 'et' --- js/index.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/js/index.js b/js/index.js index 60f9881..cecdd38 100644 --- a/js/index.js +++ b/js/index.js @@ -44,3 +44,6 @@ else { let myParagraph = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.\n\nSed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?\n\nAt vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Temporibus autem quibusdam et aut officiis debitis aut rerum necessitatibus saepe eveniet ut et voluptates repudiandae sint et molestiae non recusandae. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat."; let wordCount = myParagraph.split(" ").length; console.log(`Word count: ${wordCount}`); +//Count the word et +let etCount = myParagraph.split("et").length - 1; +console.log(`The word "et" appears ${etCount} times.`); From db741679ca44d0875c37f6781b8fc3b1aa91f822 Mon Sep 17 00:00:00 2001 From: SiyaM108 Date: Sat, 9 Aug 2025 16:05:23 +0100 Subject: [PATCH 09/10] complete pallindrome test --- js/index.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/js/index.js b/js/index.js index cecdd38..268f6e6 100644 --- a/js/index.js +++ b/js/index.js @@ -47,3 +47,27 @@ console.log(`Word count: ${wordCount}`); //Count the word et let etCount = myParagraph.split("et").length - 1; console.log(`The word "et" appears ${etCount} times.`); + +// Bonus 2: Palindrome +let phraseToCheck = "A man, a plan, a canal, Panama!"; +let testPhrase = ""; +for (let i = 0; i < phraseToCheck.length; i++) { + if (phraseToCheck[i] === " " || phraseToCheck[i] === "," || phraseToCheck[i] === "!" || phraseToCheck[i] === ".") { + ; // do nothing, skip these characters + } + else { + testPhrase += phraseToCheck[i].toLowerCase(); + } +} + +//console.log(testPhrase); +//console.log(testPhrase.length); +for (let i = 0; i < testPhrase.length / 2; i++) { + if (testPhrase[i] !== testPhrase[testPhrase.length - 1 - i]) { + console.log(`The phrase "${phraseToCheck}" is not a palindrome.`); + break; + } + if (i === Math.floor(testPhrase.length / 2) - 1) { + console.log(`The phrase "${phraseToCheck}" is a palindrome!`); + } +} From e1f47fd7cc84401019166521112f413c3fea9374 Mon Sep 17 00:00:00 2001 From: SiyaM108 Date: Sat, 9 Aug 2025 16:10:25 +0100 Subject: [PATCH 10/10] modified pallindrome --- js/index.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/js/index.js b/js/index.js index 268f6e6..4c8211f 100644 --- a/js/index.js +++ b/js/index.js @@ -62,12 +62,17 @@ for (let i = 0; i < phraseToCheck.length; i++) { //console.log(testPhrase); //console.log(testPhrase.length); +let isPalindrome = true; + for (let i = 0; i < testPhrase.length / 2; i++) { if (testPhrase[i] !== testPhrase[testPhrase.length - 1 - i]) { - console.log(`The phrase "${phraseToCheck}" is not a palindrome.`); + isPalindrome = false; break; } - if (i === Math.floor(testPhrase.length / 2) - 1) { - console.log(`The phrase "${phraseToCheck}" is a palindrome!`); - } +} + +if (isPalindrome) { + console.log(`The phrase "${phraseToCheck}" is a palindrome!`); +} else { + console.log(`The phrase "${phraseToCheck}" is not a palindrome.`); }