From 609b5e2b786a0add3726ac40903c23a81b5a2433 Mon Sep 17 00:00:00 2001 From: Victor Date: Thu, 7 Nov 2019 19:32:22 +0100 Subject: [PATCH 1/8] Added gitignore file --- .gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..722d5e71d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.vscode From bc7bed39b04bff188bbf11afa3d6204f5e782dbf Mon Sep 17 00:00:00 2001 From: Victor Date: Thu, 7 Nov 2019 19:45:49 +0100 Subject: [PATCH 2/8] Iteration 1 done --- js/index.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/js/index.js b/js/index.js index dd8ff0062..28c5a5e21 100644 --- a/js/index.js +++ b/js/index.js @@ -1,7 +1,10 @@ // Iteration 1: Names and Input +let hacker1 = "Luigi"; +console.log("The driver's name is", hacker1); +let hacker2 = "Google Chrome"; +console.log("The navigator's name is ", hacker2); // Iteration 2: Conditionals - -// Iteration 3: Loops \ No newline at end of file +// Iteration 3: Loops From 623ee0469166322021234a9dae1cc3b1e174a462 Mon Sep 17 00:00:00 2001 From: Victor Date: Thu, 7 Nov 2019 20:14:33 +0100 Subject: [PATCH 3/8] Iteration 2 done --- js/index.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/js/index.js b/js/index.js index dd8ff0062..86977a111 100644 --- a/js/index.js +++ b/js/index.js @@ -2,6 +2,14 @@ // Iteration 2: Conditionals - +let msg; +if (hacker1.length > hacker2.length) { + msg = `The driver has the longest name, it has ${hacker1.length} characters.` +} else if (hacker1.length < hacker2.length) { + msg = `It seems that the navigator has the longest name, it has ${hacker2.length} characters.` +} +else { + msg = `Wow, you both have equally long names, ${hacker1.length} characters!` +} // Iteration 3: Loops \ No newline at end of file From b15fb1fa60f0b25e7ef9d4fb500925d27bf9220c Mon Sep 17 00:00:00 2001 From: Victor Date: Thu, 7 Nov 2019 22:57:47 +0100 Subject: [PATCH 4/8] Iteration 3 done --- js/index.js | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/js/index.js b/js/index.js index dd8ff0062..35cc23ae3 100644 --- a/js/index.js +++ b/js/index.js @@ -4,4 +4,27 @@ // Iteration 2: Conditionals -// Iteration 3: Loops \ No newline at end of file +// Iteration 3: Loops +function splitLetters(str) { + let i = 0; + let chain = str[i]; + + do { + i++; + if (str[i] !== ' ') chain += ' ' + str[i]; + } while (i < str.length-1); + + return chain; +} + +console.log(splitLetters(hacker1.toUpperCase())); +console.log(hacker2.split('').reverse().join('')); + +if (hacker1 < hacker2) { + msg = "The driver's name goes first."; +} else if (hacker1 > hacker2) { + msg = "Yo, the navigator goes first definitely."; +} else { + msg = "What?! You both have the same name?"; +} +console.log(msg); \ No newline at end of file From 92fb4203762027cae74904100e16069fe3bd018f Mon Sep 17 00:00:00 2001 From: Victor Date: Fri, 8 Nov 2019 17:54:25 +0100 Subject: [PATCH 5/8] Exersice done --- js/index.js | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/js/index.js b/js/index.js index 63209ab90..dbb11f6a9 100644 --- a/js/index.js +++ b/js/index.js @@ -1,36 +1,48 @@ // Iteration 1: Names and Input -let hacker1 = "Luigi"; +console.log(">> Iteration 1 <<"); + +let hacker1 = "Mario"; console.log("The driver's name is", hacker1); -let hacker2 = "Google Chrome"; +let hacker2 = "Luigi"; console.log("The navigator's name is ", hacker2); // Iteration 2: Conditionals +console.log("\n>> Iteration 2 <<"); + let msg; if (hacker1.length > hacker2.length) { - msg = `The driver has the longest name, it has ${hacker1.length} characters.` + msg = `The driver has the longest name, it has ${hacker1.length} characters.`; } else if (hacker1.length < hacker2.length) { - msg = `It seems that the navigator has the longest name, it has ${hacker2.length} characters.` -} -else { - msg = `Wow, you both have equally long names, ${hacker1.length} characters!` + msg = `It seems that the navigator has the longest name, it has ${hacker2.length} characters.`; +} else { + msg = `Wow, you both have equally long names, ${hacker1.length} characters!`; } +console.log(msg); + // Iteration 3: Loops +console.log("\n>> Iteration 3 <<"); + function splitLetters(str) { let i = 0; let chain = str[i]; do { i++; - if (str[i] !== ' ') chain += ' ' + str[i]; - } while (i < str.length-1); + if (str[i] !== " ") chain += " " + str[i]; + } while (i < str.length - 1); return chain; } console.log(splitLetters(hacker1.toUpperCase())); -console.log(hacker2.split('').reverse().join('')); +console.log( + hacker2 + .split("") + .reverse() + .join("") +); if (hacker1 < hacker2) { msg = "The driver's name goes first."; @@ -39,4 +51,5 @@ if (hacker1 < hacker2) { } else { msg = "What?! You both have the same name?"; } + console.log(msg); From bb577a3b303f61f938f5760f4500fedea83c91f8 Mon Sep 17 00:00:00 2001 From: Victor Date: Fri, 8 Nov 2019 18:55:13 +0100 Subject: [PATCH 6/8] Bonus 1 done --- js/index.js | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/js/index.js b/js/index.js index dbb11f6a9..597e8ccfc 100644 --- a/js/index.js +++ b/js/index.js @@ -53,3 +53,55 @@ if (hacker1 < hacker2) { } console.log(msg); + +// Bonus 1 +console.log("\n>> Bonus 1 <<"); + +let lorem_chain = `Lorem ipsum dolor sit amet, consectetur adipiscing elit. +Ut magna mi, porttitor cursus tincidunt quis, blandit mattis tellus. Mauris +at lacinia leo, non efficitur nunc. Donec molestie augue magna, ut mollis ante +facilisis ac. Donec auctor odio rhoncus, sollicitudin felis eu, dignissim +nulla. Vestibulum condimentum velit ac semper interdum. Nullam blandit aliquet +est, vitae facilisis justo. Integer nulla est, pellentesque vitae rhoncus eu, +rhoncus in turpis. Proin neque est, vulputate eu aliquam a, lobortis eget lorem. +Duis suscipit sodales consequat. Pellentesque imperdiet vestibulum dui vitae +commodo. Suspendisse feugiat sit amet urna quis commodo. In feugiat ullamcorper +diam, et faucibus ex. Sed mi augue, condimentum et scelerisque vitae, viverra +non metus. Cras in velit et orci lobortis euismod in vitae tellus. Cras magna +lorem, facilisis vitae turpis in, mattis finibus mi. Morbi euismod velit in ante +semper, vitae ultricies felis lobortis. Cras diam mauris, finibus a nisl nec, +egestas ornare orci. Nam ligula leo, lacinia in blandit sed, ultrices at libero. +Vivamus gravida ante a sem commodo cursus. Proin sit amet condimentum turpis, +maximus ultricies nunc. Aliquam sit amet porttitor mi. Integer lacinia erat nec +ligula eleifend, vitae vulputate tellus venenatis. Morbi consectetur est quis +magna semper, vel malesuada erat malesuada. Mauris in quam ac libero consectetur +porttitor. Sed consectetur, libero at porttitor ullamcorper, eros lorem rhoncus +metus, vel tempor dui nisi quis nunc. Fusce lorem tortor, aliquet eu suscipit a, +iaculis a urna. In et consectetur felis. Suspendisse luctus dui ac imperdiet vehicula. +Sed placerat accumsan nisi in luctus. Cras dapibus mauris vitae eros dignissim, vel +rutrum urna sodales. Vivamus eu sapien sed odio tristique vestibulum. Donec malesuada +euismod condimentum. Mauris a odio eget odio accumsan finibus. Curabitur fringilla +pellentesque ullamcorper. Praesent tincidunt ac ipsum sed mollis. Aenean et posuere +mi, nec porttitor augue. Praesent pellentesque arcu a malesuada facilisis. Duis +velit risus, eleifend quis magna at, consectetur lacinia ipsum. Suspendisse neque +risus, tempor ut ultricies at, tempus nec enim. Praesent varius iaculis vulputate. +Etiam arcu quam, lobortis et eros eget, volutpat hendrerit justo. Nunc eget vestibulum +mi, a sollicitudin ipsum. Praesent et ipsum sagittis, sodales lacus a, volutpat sem.`; + +function countWords(chain) { + return chain.split(" ").length; +} + +function countSubstring(chain, substr) { + let count = 0; + chain = chain.split(" "); + + for (let i = 0; i < chain.length; ++i) { + if (chain[i] === substr) count++; + } + + return count; +} + +console.log("The number of words are:", countWords(lorem_chain)); +console.log(`The word 'et' it's repeats ${countSubstring(lorem_chain, "et")} times`); From cbe87bc306ef678d3062ca3516ef6bce246494df Mon Sep 17 00:00:00 2001 From: Victor Date: Fri, 8 Nov 2019 19:10:38 +0100 Subject: [PATCH 7/8] Bonus 2 begun --- js/index.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/js/index.js b/js/index.js index 597e8ccfc..1b2790df2 100644 --- a/js/index.js +++ b/js/index.js @@ -105,3 +105,8 @@ function countSubstring(chain, substr) { console.log("The number of words are:", countWords(lorem_chain)); console.log(`The word 'et' it's repeats ${countSubstring(lorem_chain, "et")} times`); + +// Bonus 2 +console.log("\n>> Bonus 2 <<"); + +let chain_forward = prompt("Introduce a chain of characters: "); \ No newline at end of file From 97644fbfb4537cbb38e26a2a99a5343acf08e58b Mon Sep 17 00:00:00 2001 From: Victor Date: Sat, 9 Nov 2019 13:51:09 +0100 Subject: [PATCH 8/8] Practices and Bonus done --- js/index.js | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/js/index.js b/js/index.js index 1b2790df2..e9e7ce4d9 100644 --- a/js/index.js +++ b/js/index.js @@ -95,7 +95,7 @@ function countWords(chain) { function countSubstring(chain, substr) { let count = 0; chain = chain.split(" "); - + for (let i = 0; i < chain.length; ++i) { if (chain[i] === substr) count++; } @@ -104,9 +104,24 @@ function countSubstring(chain, substr) { } console.log("The number of words are:", countWords(lorem_chain)); -console.log(`The word 'et' it's repeats ${countSubstring(lorem_chain, "et")} times`); +console.log( + `The word 'et' it's repeats ${countSubstring(lorem_chain, "et")} times` +); // Bonus 2 console.log("\n>> Bonus 2 <<"); -let chain_forward = prompt("Introduce a chain of characters: "); \ No newline at end of file +let chain_backward = prompt("Introduce a text:"); + +chain_backward = chain_backward.replace(/[^a-z-A-Z]/g, "").toLowerCase(); + +let chain_forward = chain_backward + .split("") + .reverse() + .join(""); + +if (chain_backward === chain_forward) { + console.log("This text is Palindrome."); +} else { + console.log("This text is NOT Palindrome."); +}