From ab2fe297b27c3134c15b8db47bf34c7093075ab8 Mon Sep 17 00:00:00 2001 From: Nazaret Date: Sun, 6 Jul 2025 17:06:29 +0200 Subject: [PATCH 1/3] Iteration 1: names and input --- js/index.js | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/js/index.js b/js/index.js index 59e4af7..95db87b 100644 --- a/js/index.js +++ b/js/index.js @@ -1,6 +1,40 @@ +console.log("I'm ready! This is just the first lab assignment."); + + // Iteration 1: Names and Input -// +const hacker1 = "Moon" +console.log(`The driver's name is ${hacker1}`) + +const hacker2 = "Sun" +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 ( hacker2.length > hacker1.length) { + console.log(`So this time the navigator has the longest name with ${hacker2.length} characters.`) +} else { + console.log(`Both have the same length! ${hacker1.length} characters.`); +} + +//Iteration 3: Loops +name1 = "" +for (character of hacker1.toUpperCase()) { + name1 += character + ' ' +} +console.log(name1.trim()) +name2 = "" +for (character of hacker2) { + name2 = hacker2.split("").reverse().join("") +} +console.log(name2) -// Iteration 3: Loops +if (hacker1.toLowerCase() < hacker2.toLowerCase()) { + console.log("The driver's name goes first."); +} else if (hacker1.toLowerCase() > hacker2.toLowerCase()) { + console.log("The navigator's name goes first definitely."); +} else { + console.log("Yeah, they've the same name already.") +} \ No newline at end of file From 4e5994146744c812321f15d4b6490a8d30e38f62 Mon Sep 17 00:00:00 2001 From: Nazaret Date: Sun, 6 Jul 2025 17:23:56 +0200 Subject: [PATCH 2/3] Iterations completed --- js/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/index.js b/js/index.js index 95db87b..5224774 100644 --- a/js/index.js +++ b/js/index.js @@ -18,7 +18,7 @@ if (hacker1.length > hacker2.length) { console.log(`Both have the same length! ${hacker1.length} characters.`); } -//Iteration 3: Loops +// Iteration 3: Loops name1 = "" for (character of hacker1.toUpperCase()) { name1 += character + ' ' From 4fa5d2afdf4b6597b11777a73cccf34af1081bab Mon Sep 17 00:00:00 2001 From: Nazaret Date: Sun, 6 Jul 2025 18:50:31 +0200 Subject: [PATCH 3/3] Iterations corrected and bonus done --- js/index.js | 40 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/js/index.js b/js/index.js index 5224774..41cf0c3 100644 --- a/js/index.js +++ b/js/index.js @@ -1,6 +1,5 @@ console.log("I'm ready! This is just the first lab assignment."); - // Iteration 1: Names and Input const hacker1 = "Moon" console.log(`The driver's name is ${hacker1}`) @@ -8,7 +7,6 @@ console.log(`The driver's name is ${hacker1}`) const hacker2 = "Sun" 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.`) @@ -19,13 +17,13 @@ if (hacker1.length > hacker2.length) { } // Iteration 3: Loops -name1 = "" +let name1 = "" for (character of hacker1.toUpperCase()) { name1 += character + ' ' } console.log(name1.trim()) -name2 = "" +let name2 = "" for (character of hacker2) { name2 = hacker2.split("").reverse().join("") } @@ -37,4 +35,38 @@ if (hacker1.toLowerCase() < hacker2.toLowerCase()) { console.log("The navigator's name goes first definitely."); } else { console.log("Yeah, they've the same name already.") +} + +// Bonus 1 +const loremIpsum = ` +Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam et justo ac nunc tincidunt tincidunt. +Vestibulum et nulla quis lorem tincidunt consequat. Aenean ut sapien sit amet elit volutpat pretium. +Nulla facilisi. Fusce et nisl ac elit dignissim sagittis. Etiam vitae justo sed purus convallis luctus. +`; + +const cleanLorem = loremIpsum.replace(/[.,!?\n]/g, ""); + +const array = cleanLorem.split(" "); +console.log(array); + +let howMany = 0; +for (word of array) { + if (word === "et") { + howMany += 1; + } +} +console.log(howMany); + +// Bonus 2 + +const phraseToCheck = "A man, a plan, a canal, Panama!" + +const cleanPhrase = phraseToCheck.toLowerCase().replace(/[\W_]/g, "") + +const reversed = cleanPhrase.split("").reverse().join("") + +if (cleanPhrase === reversed) { + console.log("Palindrome!") +} else { + console.log("No palindrome...") } \ No newline at end of file