From 1cfe77b8f1e4371382da024a0e55ac794f4f2cee Mon Sep 17 00:00:00 2001 From: Junitalama <113072416+Junitalama@users.noreply.github.com> Date: Tue, 14 Mar 2023 18:58:03 +0000 Subject: [PATCH 1/5] exercise done --- 1-exercises/A-array-find/exercise.js | 5 ++++- 1-exercises/B-array-some/exercise.js | 6 +++++- 1-exercises/C-array-every/exercise.js | 14 +++++++++++++- 1-exercises/D-array-filter/exercise.js | 17 ++++++++++++++++- 4 files changed, 38 insertions(+), 4 deletions(-) diff --git a/1-exercises/A-array-find/exercise.js b/1-exercises/A-array-find/exercise.js index 35902fed..9e6277e3 100644 --- a/1-exercises/A-array-find/exercise.js +++ b/1-exercises/A-array-find/exercise.js @@ -16,8 +16,11 @@ let names = [ "Karim", "Ahmed", ]; + function longNameWithA(name) { + return name.length > 7; +} -let longNameThatStartsWithA = findLongNameThatStartsWithA(names); +let longNameThatStartsWithA = names.find(longNameWithA); console.log(longNameThatStartsWithA); diff --git a/1-exercises/B-array-some/exercise.js b/1-exercises/B-array-some/exercise.js index fddc69ee..63a56d16 100644 --- a/1-exercises/B-array-some/exercise.js +++ b/1-exercises/B-array-some/exercise.js @@ -11,7 +11,11 @@ let pairsByIndex = [[0, 3], [1, 2], [2, 1], null, [3, 0]]; // If there is a null value in the array exit the program with the error code // https://nodejs.org/api/process.html#process_process_exit_code // process.exit(1); - + for (let pair of pairsByIndex){ + if (!pair){ + process.exit(1); + } + } let students = ["Islam", "Lesley", "Harun", "Rukmini"]; let mentors = ["Daniel", "Irina", "Mozafar", "Luke"]; diff --git a/1-exercises/C-array-every/exercise.js b/1-exercises/C-array-every/exercise.js index 347b9632..99ec31d3 100644 --- a/1-exercises/C-array-every/exercise.js +++ b/1-exercises/C-array-every/exercise.js @@ -5,7 +5,19 @@ let students = ["Omar", "Austine", "Dany", "Swathi", "Lesley", "Rukmini"]; let group = ["Austine", "Dany", "Swathi", "Daniel"]; -let groupIsOnlyStudents; // complete this statement +function containsStudent (groupWithStudents){ + for (let name of groupWithStudents){ + if(group.includes(students)){ +return true; + } else{ + return false; + } + + } + +} + +let groupIsOnlyStudents = students.every(containsStudent); if (groupIsOnlyStudents) { console.log("The group contains only students"); diff --git a/1-exercises/D-array-filter/exercise.js b/1-exercises/D-array-filter/exercise.js index 51837028..45d92dac 100644 --- a/1-exercises/D-array-filter/exercise.js +++ b/1-exercises/D-array-filter/exercise.js @@ -7,8 +7,23 @@ */ let pairsByIndexRaw = [[0, 3], [1, 2], [2, 1], null, [1], false, "whoops"]; +function validArray(pairsByIndexRaw){ + for (let item of pairsByIndexRaw){ + if(item === [0,1]){ + return true; + }else{ + return false; + } + + } +} + +let pairsByIndex = pairsByIndexRaw.filter(validArray); + + + + -let pairsByIndex; // Complete this statement let students = ["Islam", "Lesley", "Harun", "Rukmini"]; let mentors = ["Daniel", "Irina", "Mozafar", "Luke"]; From 9ab3c564e15e0c009f8c20d903662fea2a60d4b6 Mon Sep 17 00:00:00 2001 From: Junitalama <113072416+Junitalama@users.noreply.github.com> Date: Thu, 16 Mar 2023 00:21:19 +0000 Subject: [PATCH 2/5] exercise done except for each method --- 1-exercises/D-array-filter/exercise.js | 19 +++++++------------ 1-exercises/E-array-map/exercise.js | 12 +++++++++++- 1-exercises/F-array-forEach/exercise.js | 6 ++++++ 1-exercises/G-array-methods/exercise.js | 2 +- 1-exercises/G-array-methods/exercise2.js | 2 +- 1-exercises/H-array-methods-2/exercise.js | 4 ++-- 1-exercises/H-array-methods-2/exercise2.js | 7 ++++++- 1-exercises/H-array-methods-2/exercise3.js | 2 +- 1-exercises/I-string-replace/exercise.js | 2 +- 1-exercises/J-string-substring/exercise.js | 2 +- 1-exercises/J-string-substring/exercise2.js | 10 +++++----- 2-mandatory/1-create-functions.js | 9 ++++++--- 12 files changed, 48 insertions(+), 29 deletions(-) diff --git a/1-exercises/D-array-filter/exercise.js b/1-exercises/D-array-filter/exercise.js index 45d92dac..628ca2ce 100644 --- a/1-exercises/D-array-filter/exercise.js +++ b/1-exercises/D-array-filter/exercise.js @@ -7,18 +7,13 @@ */ let pairsByIndexRaw = [[0, 3], [1, 2], [2, 1], null, [1], false, "whoops"]; -function validArray(pairsByIndexRaw){ - for (let item of pairsByIndexRaw){ - if(item === [0,1]){ - return true; - }else{ - return false; - } - - } -} - -let pairsByIndex = pairsByIndexRaw.filter(validArray); + + + + + + +let pairsByIndex = pairsByIndexRaw.filter(indexes[0,1]); diff --git a/1-exercises/E-array-map/exercise.js b/1-exercises/E-array-map/exercise.js index 5a157279..07e1d23a 100644 --- a/1-exercises/E-array-map/exercise.js +++ b/1-exercises/E-array-map/exercise.js @@ -3,9 +3,19 @@ let numbers = [0.1, 0.2, 0.3, 0.4, 0.5]; -let numbersMultipliedByOneHundred; // complete this statement +/*let numbersMultipliedByOneHundred = numbers.map(function multiply(number) { + // return number * 100; +//}); +let numbersMultipliedByOneHundred = numbers.map(function(number){ + return number * 100; +}) +let numbersMultipliedByOneHundred = numbers.map(number =>{ + return number *100; +})*/ +let numbersMultipliedByOneHundred = numbers.map(number => number *100); console.log(numbersMultipliedByOneHundred); + /* EXPECTED RESULT diff --git a/1-exercises/F-array-forEach/exercise.js b/1-exercises/F-array-forEach/exercise.js index 985068cc..7296a94e 100644 --- a/1-exercises/F-array-forEach/exercise.js +++ b/1-exercises/F-array-forEach/exercise.js @@ -8,6 +8,12 @@ */ let arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]; +let multiplesOfThree = arr.map(number * 3); +let multiplesOfFive = arr.map(number * 5); +let multiplesOfBoth = arr.map(number * 3 & number *5); + +multiplesOfThree.forEach(fizz); + /* EXPECTED OUTPUT */ diff --git a/1-exercises/G-array-methods/exercise.js b/1-exercises/G-array-methods/exercise.js index 4367ef6e..bc504f2a 100644 --- a/1-exercises/G-array-methods/exercise.js +++ b/1-exercises/G-array-methods/exercise.js @@ -4,7 +4,7 @@ */ let numbers = [3, 2, 1]; -let sortedNumbers; // complete this statement +let sortedNumbers = numbers.sort(); // complete this statement /* DO NOT EDIT BELOW THIS LINE diff --git a/1-exercises/G-array-methods/exercise2.js b/1-exercises/G-array-methods/exercise2.js index 4c68c3a6..fb100649 100644 --- a/1-exercises/G-array-methods/exercise2.js +++ b/1-exercises/G-array-methods/exercise2.js @@ -7,7 +7,7 @@ let mentors = ["Daniel", "Irina", "Rares"]; let students = ["Rukmini", "Abdul", "Austine", "Swathi"]; -let everyone; // complete this statement +let everyone = mentors.concat(students); // complete this statement /* DO NOT EDIT BELOW THIS LINE diff --git a/1-exercises/H-array-methods-2/exercise.js b/1-exercises/H-array-methods-2/exercise.js index 59c5daa7..331cc4aa 100644 --- a/1-exercises/H-array-methods-2/exercise.js +++ b/1-exercises/H-array-methods-2/exercise.js @@ -15,8 +15,8 @@ let everyone = [ "Swathi", ]; -let firstFive; // complete this statement -let lastFive; // complete this statement +let firstFive = everyone.slice(0, 5); // complete this statement +let lastFive = everyone.slice(2, 7); // complete this statement /* DO NOT EDIT BELOW THIS LINE diff --git a/1-exercises/H-array-methods-2/exercise2.js b/1-exercises/H-array-methods-2/exercise2.js index 14bb4318..bfe1f3b5 100644 --- a/1-exercises/H-array-methods-2/exercise2.js +++ b/1-exercises/H-array-methods-2/exercise2.js @@ -7,7 +7,12 @@ Tip: use the string method .split() and the array method .join() */ -function capitalise(str) {} +function capitalise(str) { + let character = str.split(""); + character[0] = character[0].toUpperCase(); + return character.join(""); +} + /* DO NOT EDIT BELOW THIS LINE diff --git a/1-exercises/H-array-methods-2/exercise3.js b/1-exercises/H-array-methods-2/exercise3.js index c8e079e4..7279417e 100644 --- a/1-exercises/H-array-methods-2/exercise3.js +++ b/1-exercises/H-array-methods-2/exercise3.js @@ -7,7 +7,7 @@ let ukNations = ["Scotland", "Wales", "England", "Northern Ireland"]; function isInUK(country) { - return; // complete this statement + return ukNations.includes(country); // complete this statement } /* diff --git a/1-exercises/I-string-replace/exercise.js b/1-exercises/I-string-replace/exercise.js index 3f7104d7..0d2608ce 100644 --- a/1-exercises/I-string-replace/exercise.js +++ b/1-exercises/I-string-replace/exercise.js @@ -13,7 +13,7 @@ let story = "I like dogs. One day I went to the park and I saw 10 dogs. It was a great day."; -let result = story.replace("", ""); +let result = story.replace("dogs", "cats") .replace("day","night") .replace("10","10000") .replace("great","brilliant") .replace("day","night"); /* EXPECTED OUTPUT */ diff --git a/1-exercises/J-string-substring/exercise.js b/1-exercises/J-string-substring/exercise.js index 4624db68..85c9713f 100644 --- a/1-exercises/J-string-substring/exercise.js +++ b/1-exercises/J-string-substring/exercise.js @@ -6,7 +6,7 @@ let statement = "I like programming and dogs"; -statement = statement.substring(); +statement = statement.substring(7,statement.length); console.log(statement); diff --git a/1-exercises/J-string-substring/exercise2.js b/1-exercises/J-string-substring/exercise2.js index a1d9bf62..e0e4e1f7 100644 --- a/1-exercises/J-string-substring/exercise2.js +++ b/1-exercises/J-string-substring/exercise2.js @@ -14,11 +14,11 @@ let names = [ "Arron Graham", ]; -names[0] = names[0].substring(); -names[1] = names[1].substring(); -names[2] = names[2].substring(); -names[3] = names[3].substring(); -names[4] = names[4].substring(); +names[0] = names[0].substring(0,6); +names[1] = names[1].substring(0,7); +names[2] = names[2].substring(0,4); +names[3] = names[3].substring(0,4); +names[4] = names[4].substring(0,5); names.forEach((name) => { console.log(name); diff --git a/2-mandatory/1-create-functions.js b/2-mandatory/1-create-functions.js index 6df12961..ca77a3e0 100644 --- a/2-mandatory/1-create-functions.js +++ b/2-mandatory/1-create-functions.js @@ -3,15 +3,18 @@ Write a function that: - Accepts an array as a parameter. - Returns a new array containing the first five elements of the passed array. */ -function first5() { -} +function first5(numbers) { + let newArr =numbers.slice(0,5); + return newArr; + /* Write a function that: - Accepts an array as a parameter. - Returns a new array containing the same elements, except sorted. */ -function sortArray() { +function sortArray(arr) { + return arr.slice().sort(); } /* From 1dc89101c6d1b4692c1131ccf5f3ec9e2efe2c3d Mon Sep 17 00:00:00 2001 From: Junitalama <113072416+Junitalama@users.noreply.github.com> Date: Fri, 17 Mar 2023 02:07:41 +0000 Subject: [PATCH 3/5] done some mandatory --- 1-exercises/J-string-substring/exercise3.js | 5 +---- 2-mandatory/1-create-functions.js | 17 +++++++++++------ 2-mandatory/2-oxygen-levels.js | 6 +++++- 2-mandatory/4-space-colonies.js | 5 ++++- 2-mandatory/5-eligible-students.js | 5 ++++- 2-mandatory/6-journey-planner.js | 5 +++-- 2-mandatory/7-lane-names.js | 7 ++++++- 2-mandatory/8-password-validator.js | 2 +- 8 files changed, 35 insertions(+), 17 deletions(-) diff --git a/1-exercises/J-string-substring/exercise3.js b/1-exercises/J-string-substring/exercise3.js index 14f77417..d783c366 100644 --- a/1-exercises/J-string-substring/exercise3.js +++ b/1-exercises/J-string-substring/exercise3.js @@ -6,10 +6,7 @@ HINT: You will need to use .substring() twice */ -let statement = "I do not like programming"; - -let result = ""; - +let statement = "I do not like programming" console.log(result); /* EXPECTED OUTPUT diff --git a/2-mandatory/1-create-functions.js b/2-mandatory/1-create-functions.js index ca77a3e0..388a5fd8 100644 --- a/2-mandatory/1-create-functions.js +++ b/2-mandatory/1-create-functions.js @@ -3,9 +3,9 @@ Write a function that: - Accepts an array as a parameter. - Returns a new array containing the first five elements of the passed array. */ -function first5(numbers) { - let newArr =numbers.slice(0,5); - return newArr; +function first5(arr) { + let newArr =arr.slice(0,5); + return newArr;} /* @@ -27,7 +27,8 @@ Write a function that: - Removes any forward slashes (/) in the strings. - Makes the strings all lowercase. */ -function tidyUpString() { +function tidyUpString(array) { + } /* @@ -36,7 +37,10 @@ Write a function that: - Returns a new array containing the same elements, but without the element at the passed index. */ -function remove() { +function remove(array,index) { + let arr =array.slice(); + arr.splice(index,1); + return arr; } /* @@ -47,7 +51,8 @@ Write a function that: - Numbers greater 100 must be replaced with 100. */ -function formatPercentage() { +function formatPercentage(numbers) { + return } /* ======= TESTS - DO NOT MODIFY ===== */ diff --git a/2-mandatory/2-oxygen-levels.js b/2-mandatory/2-oxygen-levels.js index 5711c5e5..4c77d25b 100644 --- a/2-mandatory/2-oxygen-levels.js +++ b/2-mandatory/2-oxygen-levels.js @@ -11,7 +11,11 @@ Some string methods that might help you here are .replace() and .substring(). */ -function findSafeOxygenLevel() {} +function findSafeOxygenLevel(oxygenLevels) { + + } + + /* ======= TESTS - DO NOT MODIFY ===== */ diff --git a/2-mandatory/4-space-colonies.js b/2-mandatory/4-space-colonies.js index 30095213..83bbb1ca 100644 --- a/2-mandatory/4-space-colonies.js +++ b/2-mandatory/4-space-colonies.js @@ -15,7 +15,10 @@ */ -function getSettlers() {} +function getSettlers(families) { + let family = families.filter(word=>word.startsWith("A") && word.endsWith("family")) + return family; +} /* ======= TESTS - DO NOT MODIFY ===== */ diff --git a/2-mandatory/5-eligible-students.js b/2-mandatory/5-eligible-students.js index f92478e0..3baefdd7 100644 --- a/2-mandatory/5-eligible-students.js +++ b/2-mandatory/5-eligible-students.js @@ -7,7 +7,10 @@ - Returns an array containing only the names of the who have attended AT LEAST 8 classes */ -function getEligibleStudents() {} +function getEligibleStudents(students, attendance) { + let studentName = students.filter(attendance=>attendance[1]>=8) + return studentName.map(names=>names[0]); +} /* ======= TESTS - DO NOT MODIFY ===== */ diff --git a/2-mandatory/6-journey-planner.js b/2-mandatory/6-journey-planner.js index 25a14083..2b617db7 100644 --- a/2-mandatory/6-journey-planner.js +++ b/2-mandatory/6-journey-planner.js @@ -19,9 +19,10 @@ function checkCodeIsThere(stringText) { let magicWord = "code"; + //edit code below - if (stringText) { - return stringText; + if (stringText.includes(magicWord)) { + return stringText.indexOf(magicWord); } else { return "Not found"; } diff --git a/2-mandatory/7-lane-names.js b/2-mandatory/7-lane-names.js index 40c31b68..1cac20bd 100644 --- a/2-mandatory/7-lane-names.js +++ b/2-mandatory/7-lane-names.js @@ -6,7 +6,12 @@ HINT: string and array methods that could be helpful (indexOf, filter) */ -function getLanes() {} +function getLanes(streets) { + return streets.filter(street => street.includes("Lane")) + + } + + /* ======= TESTS - DO NOT MODIFY ===== */ diff --git a/2-mandatory/8-password-validator.js b/2-mandatory/8-password-validator.js index dc3e84d6..51020c12 100644 --- a/2-mandatory/8-password-validator.js +++ b/2-mandatory/8-password-validator.js @@ -27,7 +27,7 @@ function validatePasswords(passwords) {} // Returns true if string contains at least one uppercase letter. function containsUppercaseLetter(string) { - return /[A-Z]/.test(string); + return string.test(string); } // Returns true if string contains at least one lowercase letter. From df0cf31e84dd5272fd899f74eb645c9caca1c038 Mon Sep 17 00:00:00 2001 From: Junitalama <113072416+Junitalama@users.noreply.github.com> Date: Sat, 18 Mar 2023 16:16:47 +0000 Subject: [PATCH 4/5] Update exercise.js --- 1-exercises/F-array-forEach/exercise.js | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/1-exercises/F-array-forEach/exercise.js b/1-exercises/F-array-forEach/exercise.js index 7296a94e..512a16fc 100644 --- a/1-exercises/F-array-forEach/exercise.js +++ b/1-exercises/F-array-forEach/exercise.js @@ -8,11 +8,27 @@ */ let arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]; -let multiplesOfThree = arr.map(number * 3); -let multiplesOfFive = arr.map(number * 5); -let multiplesOfBoth = arr.map(number * 3 & number *5); +arr.forEach(n => { + if(n % 3 === 0 && n % 5 === 0){ + console.log("FizzBuzz");} + else if(n % 3 === 0){ + console.log("Fizz");} + else if(n % 5 === 0){ + console.log("Buzz");} + else{ + console.log(n); + } + + + +} +); + +// let multiplesOfThree = arr.map(number * 3); +// let multiplesOfFive = arr.map(number * 5); +// let multiplesOfBoth = arr.map(number * 3 & number *5); + -multiplesOfThree.forEach(fizz); /* EXPECTED OUTPUT */ From 60fa80dac20d2d58948737d450b567e9e78308b7 Mon Sep 17 00:00:00 2001 From: Junitalama <113072416+Junitalama@users.noreply.github.com> Date: Mon, 20 Mar 2023 00:49:17 +0000 Subject: [PATCH 5/5] mandatory --- 1-exercises/A-array-find/exercise.js | 8 ++++---- 1-exercises/C-array-every/exercise.js | 6 +++--- 1-exercises/D-array-filter/exercise.js | 3 ++- 1-exercises/F-array-forEach/exercise.js | 3 --- 2-mandatory/1-create-functions.js | 21 ++++++++++++++++++--- 2-mandatory/2-oxygen-levels.js | 10 ++++++++-- 2-mandatory/3-bush-berries.js | 10 ++++++++-- 2-mandatory/6-journey-planner.js | 18 +++++++++++++++--- 2-mandatory/8-password-validator.js | 5 ++++- 9 files changed, 62 insertions(+), 22 deletions(-) diff --git a/1-exercises/A-array-find/exercise.js b/1-exercises/A-array-find/exercise.js index 9e6277e3..d63fa35b 100644 --- a/1-exercises/A-array-find/exercise.js +++ b/1-exercises/A-array-find/exercise.js @@ -16,11 +16,11 @@ let names = [ "Karim", "Ahmed", ]; - function longNameWithA(name) { - return name.length > 7; -} + //function longNameWithA(name) { + // return name.length > 7; +//} -let longNameThatStartsWithA = names.find(longNameWithA); +let longNameThatStartsWithA = names.find(name => name.length > 7); console.log(longNameThatStartsWithA); diff --git a/1-exercises/C-array-every/exercise.js b/1-exercises/C-array-every/exercise.js index 99ec31d3..2486b64f 100644 --- a/1-exercises/C-array-every/exercise.js +++ b/1-exercises/C-array-every/exercise.js @@ -5,7 +5,7 @@ let students = ["Omar", "Austine", "Dany", "Swathi", "Lesley", "Rukmini"]; let group = ["Austine", "Dany", "Swathi", "Daniel"]; -function containsStudent (groupWithStudents){ +/*function containsStudent (groupWithStudents){ for (let name of groupWithStudents){ if(group.includes(students)){ return true; @@ -15,9 +15,9 @@ return true; } -} +}*/ -let groupIsOnlyStudents = students.every(containsStudent); +let groupIsOnlyStudents = students.every(name => group.includes(students)? true : false); if (groupIsOnlyStudents) { console.log("The group contains only students"); diff --git a/1-exercises/D-array-filter/exercise.js b/1-exercises/D-array-filter/exercise.js index 628ca2ce..0635b0d9 100644 --- a/1-exercises/D-array-filter/exercise.js +++ b/1-exercises/D-array-filter/exercise.js @@ -13,7 +13,8 @@ let pairsByIndexRaw = [[0, 3], [1, 2], [2, 1], null, [1], false, "whoops"]; -let pairsByIndex = pairsByIndexRaw.filter(indexes[0,1]); +let pairsByIndex = pairsByIndexRaw.filter(item => Array.isArray(item) && item.length === 2); + diff --git a/1-exercises/F-array-forEach/exercise.js b/1-exercises/F-array-forEach/exercise.js index 512a16fc..f834d5c6 100644 --- a/1-exercises/F-array-forEach/exercise.js +++ b/1-exercises/F-array-forEach/exercise.js @@ -24,9 +24,6 @@ arr.forEach(n => { } ); -// let multiplesOfThree = arr.map(number * 3); -// let multiplesOfFive = arr.map(number * 5); -// let multiplesOfBoth = arr.map(number * 3 & number *5); diff --git a/2-mandatory/1-create-functions.js b/2-mandatory/1-create-functions.js index 388a5fd8..2c05d6a1 100644 --- a/2-mandatory/1-create-functions.js +++ b/2-mandatory/1-create-functions.js @@ -27,8 +27,14 @@ Write a function that: - Removes any forward slashes (/) in the strings. - Makes the strings all lowercase. */ -function tidyUpString(array) { - +function tidyUpString(arr) { + newArr = arr.map(function (string) { + string = string.trim(); + string = string.replace("/", ""); + string = string.toLowerCase(); + return string; + }); + return newArr; } /* @@ -52,7 +58,16 @@ Write a function that: */ function formatPercentage(numbers) { - return + let newnumbers = numbers.map(function (number) { + if (number > 100) { + number = "100%"; + } else { + number = `${Math.round(number * 100) / 100}%`; + } + + return number; + }); + return newnumbers; } /* ======= TESTS - DO NOT MODIFY ===== */ diff --git a/2-mandatory/2-oxygen-levels.js b/2-mandatory/2-oxygen-levels.js index 4c77d25b..724c134e 100644 --- a/2-mandatory/2-oxygen-levels.js +++ b/2-mandatory/2-oxygen-levels.js @@ -12,8 +12,14 @@ */ function findSafeOxygenLevel(oxygenLevels) { - - } +let planets=oxygenLevels.filter(oxygenLevel =>oxygenLevel.includes("%")) +let numberLevels= planets.map(number => parseFloat(number)) +let safePlanets=numberLevels.find(level => level> 19.5 && level<23.5) +if(safePlanets!==undefined){ + return `${safePlanets}%`; +} + +} diff --git a/2-mandatory/3-bush-berries.js b/2-mandatory/3-bush-berries.js index b434a507..9cc5c352 100644 --- a/2-mandatory/3-bush-berries.js +++ b/2-mandatory/3-bush-berries.js @@ -21,8 +21,14 @@ Let's first look at an example that will teach you how to use these methods. */ -function isBushSafe(berryArray) { - //Write your code here +function isBushSafe(berryArray) { + let safeBush = berryArray.every(berry => berry.includes("pink")) + if(safeBush){ + return "Bush is safe to eat from" + }else{ + return "Toxic! Leave bush alone!" + + } } /* ======= TESTS - DO NOT MODIFY ===== */ diff --git a/2-mandatory/6-journey-planner.js b/2-mandatory/6-journey-planner.js index 2b617db7..3bc8a116 100644 --- a/2-mandatory/6-journey-planner.js +++ b/2-mandatory/6-journey-planner.js @@ -65,7 +65,9 @@ function checkCodeIsThere(stringText) { Hint: Use the corresponding array method to split the array. */ -function getTransportModes() {} +function getTransportModes(location) { + return location.slice(1) +} /* Implement the function isAccessibleByTransportMode that @@ -82,7 +84,12 @@ function getTransportModes() {} Hint: Use the corresponding array method to decide if an element is included in an array. */ -function isAccessibleByTransportMode() {} +function isAccessibleByTransportMode(arr, str) { + if(arr.includes(str)){ + return true; +} else +return false; +} /* Implement the function getLocationName that @@ -93,7 +100,9 @@ function isAccessibleByTransportMode() {} - Returns the name of the location e.g: "Tower Bridge" */ -function getLocationName() {} +function getLocationName(locations) { + return locations.at(0); +} /* We arrived at the final method. it won't take long if you use the previously implemented functions wisely. @@ -124,8 +133,11 @@ function getLocationName() {} */ function journeyPlanner(locations, transportMode) { // Implement the function body +let accessibleLocations= locations.filter( location=> location.includes(transportMode)) +return accessibleLocations.map(getLocationName) } + /* ======= TESTS - DO NOT MODIFY ===== */ const string1 = "I Love coding and perfect code makes me happy"; diff --git a/2-mandatory/8-password-validator.js b/2-mandatory/8-password-validator.js index 51020c12..9515b647 100644 --- a/2-mandatory/8-password-validator.js +++ b/2-mandatory/8-password-validator.js @@ -23,7 +23,10 @@ PasswordValidationResult= [false, false, false, false, true] */ -function validatePasswords(passwords) {} + + + + // Returns true if string contains at least one uppercase letter. function containsUppercaseLetter(string) {