From e4305024689b8301bd6c178854ff9e60d195adbb Mon Sep 17 00:00:00 2001 From: theresajvrensburg Date: Sat, 19 Oct 2024 11:19:12 +0200 Subject: [PATCH 1/2] Solved Laab --- .idea/.gitignore | 8 +++++ .idea/lab-javascript-basic-algorithms.iml | 9 ++++++ .idea/misc.xml | 9 ++++++ .idea/modules.xml | 8 +++++ .idea/vcs.xml | 6 ++++ index.js | 38 ++++++++++++++++++++++- 6 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/lab-javascript-basic-algorithms.iml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 000000000..13566b81b --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/lab-javascript-basic-algorithms.iml b/.idea/lab-javascript-basic-algorithms.iml new file mode 100644 index 000000000..d6ebd4805 --- /dev/null +++ b/.idea/lab-javascript-basic-algorithms.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 000000000..fcd3b053c --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 000000000..d21394e9d --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 000000000..35eb1ddfb --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/index.js b/index.js index 6b0fec3ad..20d9ad5a3 100644 --- a/index.js +++ b/index.js @@ -1,7 +1,43 @@ // Iteration 1: Names and Input - +//1.1 +let hacker1 = "Simon-Garfunkle"; +//1.2 +console.log("The driver's name is " + hacker1); +//1.3 +let hacker2 = "Laura-Ashley"; +//1.4 +console.log("The navigator's name is " + hacker2); // Iteration 2: Conditionals +//2.1 +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(`The navigator has the longest name, it has ${hacker2.length} characters`); +}else{ + let equal = hacker1.length === hacker2.length ? hacker1.length : false; + console.log(`Wow, you both have equally long names, ${equal} characters!`); +} // Iteration 3: Loops +//3.1 +let hacker1Altered = ""; +for(let i=0; i=0; j--){ + hacker2Altered += hacker2[j]; +} +console.log(hacker2Altered); +//3.3 +// To sort the strings we can use the inbuilt sort() function, but to compare it they need to be part of the same structure. +// The function sorts the string in lexicographical order by default (alphabetical also making comparison using the whole length of the string +// with length). +let comparison = [hacker1, hacker2].sort(); +console.log(comparison); + + From 82075c17684654b0a9aeba2c2a674d4243a1c2db Mon Sep 17 00:00:00 2001 From: theresajvrensburg Date: Sun, 20 Oct 2024 00:10:56 +0200 Subject: [PATCH 2/2] Solved Lab --- index.js | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 90 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 20d9ad5a3..a488f10b4 100644 --- a/index.js +++ b/index.js @@ -8,6 +8,7 @@ let hacker2 = "Laura-Ashley"; //1.4 console.log("The navigator's name is " + hacker2); +console.log("===================== end ITR1 =========================="); // Iteration 2: Conditionals //2.1 if(hacker1.length > hacker2.length){ @@ -15,11 +16,10 @@ if(hacker1.length > hacker2.length){ }else if(hacker1.length < hacker2.length){ console.log(`The navigator has the longest name, it has ${hacker2.length} characters`); }else{ - let equal = hacker1.length === hacker2.length ? hacker1.length : false; - console.log(`Wow, you both have equally long names, ${equal} characters!`); + console.log(`Wow, you both have equally long names, ${hacker1.length} characters!`); } - +console.log("===================== end ITR2 =========================="); // Iteration 3: Loops //3.1 let hacker1Altered = ""; @@ -40,4 +40,91 @@ console.log(hacker2Altered); let comparison = [hacker1, hacker2].sort(); console.log(comparison); +console.log("===================== end ITR3 =========================="); +// Bonus questions: +// Bonus 1: +// Generated 3 paragraphs, 1912 bytes of Lorem Ipsum +const longText = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce nulla mauris, posuere ut malesuada et, aliquet nec mauris. " + + "Phasellus id odio porttitor, fringilla tellus maximus, molestie neque. Donec id urna vel diam ornare hendrerit. Nunc egestas felis eget consequat " + + "dapibus. Nam congue dolor ac odio tempor, in malesuada mi efficitur. Mauris vitae vulputate ante. Integer iaculis bibendum dui et sagittis. " + + "Phasellus at consequat turpis, at porta justo. Nunc sollicitudin vulputate dolor. Pellentesque vitae velit rhoncus, mollis sapien ut, rhoncus augue. " + + "Cras lectus quam, egestas bibendum lacus a, suscipit egestas velit. Aliquam efficitur urna ac dui lobortis tincidunt. Donec quis congue nisi. " + + "In elementum risus dolor, ac rutrum nulla commodo nec. Phasellus et efficitur diam, at varius elit. Proin vestibulum scelerisque bibendum. " + + "Praesent lacinia in metus nec vulputate. Vestibulum ullamcorper finibus eros euismod gravida. Fusce in molestie velit. Ut facilisis ac lacus non eleifend." + + "Nullam vehicula viverra orci ut vestibulum. Nulla a ultrices metus. Donec faucibus sollicitudin nulla at rhoncus. Ut tincidunt at turpis quis aliquam. " + + "Morbi vehicula, neque at pharetra elementum, augue eros rhoncus ex, sit amet venenatis est sapien vitae elit. Nullam scelerisque, orci aliquam malesuada " + + "ullamcorper, tellus urna ultricies sem, in suscipit ipsum diam consequat ipsum. Vestibulum non nisi risus. Ut sit amet pharetra neque, ac scelerisque nisi." + + "Duis accumsan risus sed neque fringilla, ut feugiat mauris pellentesque. Phasellus lobortis consectetur magna, vel aliquam enim luctus porta. " + + "Phasellus ac porta velit, at commodo nisi. Phasellus sed tempus sapien, quis iaculis sem. Vivamus accumsan ex nulla, eu aliquet ligula faucibus et. " + + "Donec varius ipsum at orci bibendum molestie. Nulla facilisi. Integer sed luctus risus, ut placerat leo. Vestibulum at lectus scelerisque, gravida erat " + + "et, aliquam sapien." + +// Make your program count the number of words in the string. +function wordCounter(str){ + return str.split(" ").length; +} + +console.log(wordCounter(longText)); + +// Make your program count the number of times the Latin word et appears. +function countEt(str) { + let nstr = str.split(" "); + //console.log(nstr); + let counter = 0; + for(let i=0; i=0; i--){ + reversestr += reformat(phraseToCheck[i]); + } + + console.log(strippedString); + console.log(reversestr); + + if(strippedString === reversestr){ + return true; + } else { + return false; + } + +} +console.log(palindromeChecker(phraseToCheck)); +console.log(palindromeChecker("Begin challenging your own assumptions."));