From 86a85d2440785066511680dc983eccbe78c93870 Mon Sep 17 00:00:00 2001 From: azadaafo Date: Sun, 10 May 2020 17:41:16 +0100 Subject: [PATCH 01/11] oxygen and bush-berries exercises done --- week-3/Homework/mandatory/1-oxygen-levels.js | 14 +++++++++++--- week-3/Homework/mandatory/2-bush-berries.js | 11 ++++++++--- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/week-3/Homework/mandatory/1-oxygen-levels.js b/week-3/Homework/mandatory/1-oxygen-levels.js index a105fdeb8..1124e9731 100644 --- a/week-3/Homework/mandatory/1-oxygen-levels.js +++ b/week-3/Homework/mandatory/1-oxygen-levels.js @@ -26,9 +26,17 @@ console.log(newdessert); // returns ice cream /* + + + + + + + */ /* Now try the exercise */ - -function safeLevels() { - +function safeLevels(arrStr) { + //first solution + let levelNumber = arrStr.map((level) => { + let removingPercentage = level.substring(0, 4); + let stringToNumber = parseFloat(removingPercentage); + return stringToNumber; + }); + let findOxyArray = levelNumber.find( + (findOxy) => findOxy > 19.5 && findOxy < 23.5 + ); + return findOxyArray + "%"; } /* ======= TESTS - DO NOT MODIFY ===== */ diff --git a/week-3/Homework/mandatory/2-bush-berries.js b/week-3/Homework/mandatory/2-bush-berries.js index ea5118004..21b7efac4 100644 --- a/week-3/Homework/mandatory/2-bush-berries.js +++ b/week-3/Homework/mandatory/2-bush-berries.js @@ -27,9 +27,14 @@ values will have a remainder of 0 i.e. there are some odd numbers in the array t /* + + + + + + + + + + + + + + */ /* Now try to complete the exercise */ - -function bushChecker() { - +function bushChecker(colourBush) { + let checkPink = colourBush.every((berriesPink) => berriesPink === "pink"); + if (checkPink) { + //you can also write if (arr.every(pinkBerries => pinkBerries === "pink")) + return "Bush is safe to eat from"; + } else { + return "Toxic! Leave bush alone!"; + } } /* ======= TESTS - DO NOT MODIFY ===== */ From 71998e6732237f1abfd0b87b5457513acf4b857d Mon Sep 17 00:00:00 2001 From: azadaafo Date: Sun, 10 May 2020 17:43:24 +0100 Subject: [PATCH 02/11] coloniser exercise doen --- week-3/Homework/mandatory/3-space-colonies.js | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/week-3/Homework/mandatory/3-space-colonies.js b/week-3/Homework/mandatory/3-space-colonies.js index f9e7ba636..271276269 100644 --- a/week-3/Homework/mandatory/3-space-colonies.js +++ b/week-3/Homework/mandatory/3-space-colonies.js @@ -13,8 +13,29 @@ */ -function colonisers() {} +function colonisers(families) { + return families.filter( + (checkNames) => + checkNames.charAt(0) === "A" && checkNames.includes("family") + ); +} +console.log( + colonisers([ + "Adam family", + "Potter family", + "Eric", + "Aldous", + "Button family", + "Jude", + "Carmichael", + "Bunny", + "Asimov", + "Oscar family", + "Avery family", + "Archer family", + ]) +); /* ======= TESTS - DO NOT MODIFY ===== */ const voyagers = [ From d85af8b552abf39eb46aa362e1b5c2b9a71a2dd3 Mon Sep 17 00:00:00 2001 From: azadaafo Date: Sun, 10 May 2020 17:47:43 +0100 Subject: [PATCH 03/11] 4-eligible-students done --- week-3/Homework/mandatory/4-eligible-students.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/week-3/Homework/mandatory/4-eligible-students.js b/week-3/Homework/mandatory/4-eligible-students.js index e72ddedb1..8a3e1bfad 100644 --- a/week-3/Homework/mandatory/4-eligible-students.js +++ b/week-3/Homework/mandatory/4-eligible-students.js @@ -53,7 +53,14 @@ console.log(arrayLengths); /* + + + + + + + */ /* Now try the exercise */ -function getEligibleStudents() { +function getEligibleStudents(studentsEligible) { + let studentAttendancyCheck = studentsEligible.filter( + (attendancyCheck) => attendancyCheck[1] >= 8 + ); + let NameOfStudentAttendancyChecked = studentAttendancyCheck.map( + (attendancyCheck) => attendancyCheck[0] + ); + return NameOfStudentAttendancyChecked; } /* @@ -72,7 +79,12 @@ function getEligibleStudents() { Hint: To complete the function, search how to change text to lower or upper case by using string method. */ -function getEligibleStudents2() { +function getEligibleStudents2(sameNameStudent) { + return sameNameStudent + .filter((checkStudentsNames) => + checkStudentsNames[0].toUpperCase().startsWith("A") + ) + .map((studentWithLetterA) => studentWithLetterA[0]); } /* ======= TESTS - DO NOT MODIFY ===== */ From 3468bb8b5e0fb98371b8ecfd4d2fca5476b027d3 Mon Sep 17 00:00:00 2001 From: azadaafo Date: Sun, 10 May 2020 17:51:40 +0100 Subject: [PATCH 04/11] 5-journey-planner done --- .../Homework/mandatory/5-journey-planner.js | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/week-3/Homework/mandatory/5-journey-planner.js b/week-3/Homework/mandatory/5-journey-planner.js index 0ac48b8cd..521563ba2 100644 --- a/week-3/Homework/mandatory/5-journey-planner.js +++ b/week-3/Homework/mandatory/5-journey-planner.js @@ -23,8 +23,9 @@ function checkCodeIsThere(stringText) { let magicWord = "code"; //edit code below - if (stringText) { - return stringText; + if (stringText.includes(magicWord)) { + // you can also use if(stringText.indexOf(magicWord)>=0) + return stringText.indexOf(magicWord); } else { return "Not found"; } @@ -68,8 +69,9 @@ function checkCodeIsThere(stringText) { Hint: Use the corresponding array method to split the array. */ -function getTransportModes() { } - +function getTransportModes(travelDetails) { + return travelDetails.slice(1); // returns last 2 items of the array, does not have the first item +} /* Implement the function isAccessibleByTransportMode that - Accepts two parameters: @@ -84,8 +86,9 @@ function getTransportModes() { } Hint: Use the corresponding array method to decide if an element is member of an array. */ -function isAccessibleByTransportMode() { } - +function isAccessibleByTransportMode(transportModes, transport) { + return transportModes.includes(transport); // returns a boolean value +} /* Implement the function getLocationName that - Accepts a location and available transports in an array @@ -93,8 +96,9 @@ function isAccessibleByTransportMode() { } - Returns the name of the location e.g: "Tower Bridge" */ -function getLocationName() { } - +function getLocationName(travelDetails) { + return travelDetails[0]; // "Tower Bridge" - student must return this string +} /* We arrived at the final method. it won't take long if you use the previously implemented functions wisely. @@ -121,6 +125,14 @@ function getLocationName() { } */ function journeyPlanner(locations, transportMode) { // Implement the function body + const travelablelocations = locations + .filter((location) => location.includes(transportMode)) // filter correct location details + .map((location) => { + const locationName = location[0]; // grab the string name, which is the first string at the start + return locationName; + }); + + return travelablelocations; } /* ======= TESTS - DO NOT MODIFY ===== */ From a7ea06d0750c1b19cbdb0e43e4f2a13415f0fa42 Mon Sep 17 00:00:00 2001 From: azadaafo Date: Sun, 10 May 2020 17:52:55 +0100 Subject: [PATCH 05/11] 6-lane-names done --- week-3/Homework/mandatory/6-lane-names.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/week-3/Homework/mandatory/6-lane-names.js b/week-3/Homework/mandatory/6-lane-names.js index caf88c4ca..360205499 100644 --- a/week-3/Homework/mandatory/6-lane-names.js +++ b/week-3/Homework/mandatory/6-lane-names.js @@ -5,9 +5,10 @@ */ //hint: string and array methods that could be helpful (indexOf, filter) -function getLanes() { - -} +function getLanes(names) { + const targetName = "Lane"; // string 'Lane' needs to be used + return names.filter((name) => name.includes(targetName)); + } /* ======= TESTS - DO NOT MODIFY ===== */ From 2501105db3cedc23e5cc57edc0d68a671e99720f Mon Sep 17 00:00:00 2001 From: azadaafo Date: Tue, 7 Jul 2020 00:23:00 +0100 Subject: [PATCH 06/11] failed oxygen level exercise --- week-3/Homework/mandatory/1-oxygen-levels.js | 51 ++++++++------------ 1 file changed, 19 insertions(+), 32 deletions(-) diff --git a/week-3/Homework/mandatory/1-oxygen-levels.js b/week-3/Homework/mandatory/1-oxygen-levels.js index 1124e9731..16ed5bc23 100644 --- a/week-3/Homework/mandatory/1-oxygen-levels.js +++ b/week-3/Homework/mandatory/1-oxygen-levels.js @@ -1,42 +1,29 @@ /* Many years into the future, a team of Space Voyagers find their ship is low on Oxygen and need to dock somewhere safe while they call home for help. - Their computer detects a list of nearby planets that have Oxygen in their atmosphere. - To be safe, they need to land on the first unamed planet that has Oxygen levels between 19.5% and 23.5%. - Write a function that finds the oxygen level of the first safe planet - Oxygen between 19.5% and 23.5% - Some string methods that might help you here are .replace() and .substring(). Let's look at a quick example before trying the exercise. */ - /* .replace() allows us to add something where we removed something*/ let greeting = "Good Morning"; greeting.replace('Morning', 'Evening'); // outputs Good Evening - - /* .substring() allows us to remove things from strings */ let dessert = "ice cream and pancakes"; - let newdessert = dessert.substring(0, 9); - console.log(newdessert); // returns ice cream /* + + + + + + + */ /* Now try the exercise */ -function safeLevels(arrStr) { - //first solution - let levelNumber = arrStr.map((level) => { - let removingPercentage = level.substring(0, 4); - let stringToNumber = parseFloat(removingPercentage); - return stringToNumber; - }); - let findOxyArray = levelNumber.find( - (findOxy) => findOxy > 19.5 && findOxy < 23.5 - ); - return findOxyArray + "%"; + +function safeLevels() { + if (oxygenLevels1 >= "19.5%" && oxygenLevels1 <= "23.5%") { + return `oxygen level is safe` + } else { + `oxygen level is not safe` + } } /* ======= TESTS - DO NOT MODIFY ===== */ @@ -45,22 +32,22 @@ const oxygenLevels1 = ["24.2%", "11.3%", "19.9%", "23.1%", "29.3%", "20.2%"] const oxygenLevels2 = ["30.8%", "23.5%", "18.8%", "19.5%", "20.2%", "31.6%"] function test(test_name, expr) { - let status; - if (expr) { - status = "PASSED"; - } else { - status = "FAILED"; - } - - console.log(`${test_name}: ${status}`); + let status; + if (expr) { + status = "PASSED"; + } else { + status = "FAILED"; + } + + console.log(`${test_name}: ${status}`); } test( - "safeLevels function works - case 2", - safeLevels(oxygenLevels1) === "19.9%" + "safeLevels function works - case 2", + safeLevels(oxygenLevels1) === "19.9%" ); test( - "safeLevels function works - case 2", - safeLevels(oxygenLevels2) === "20.2%" + "safeLevels function works - case 2", + safeLevels(oxygenLevels2) === "20.2%" ); \ No newline at end of file From 2dedc1ab18581cd69fd74098c7d20c5afd8b2361 Mon Sep 17 00:00:00 2001 From: azadaafo Date: Tue, 7 Jul 2020 00:42:33 +0100 Subject: [PATCH 07/11] bush-berries task failed --- week-3/Homework/mandatory/2-bush-berries.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/week-3/Homework/mandatory/2-bush-berries.js b/week-3/Homework/mandatory/2-bush-berries.js index 21b7efac4..9b461b34d 100644 --- a/week-3/Homework/mandatory/2-bush-berries.js +++ b/week-3/Homework/mandatory/2-bush-berries.js @@ -18,22 +18,22 @@ let array = [12, 73, 92, 45, 100, 14, 61]; -array.some((value) => {return (value % 2 == 0)}); /* this will return true as SOME values +array.some((value) => { return (value % 2 == 0) }); /* this will return true as SOME values will have a remainder of 0 i.e. they are even numbers*/ -array.every((value) => {return (value % 2 == 0)}); /* this will return false as not ALL +array.every((value) => { return (value % 2 == 0) }); /* this will return false as not ALL values will have a remainder of 0 i.e. there are some odd numbers in the array too*/ /* + + + + + + + + + + + + + + */ /* Now try to complete the exercise */ -function bushChecker(colourBush) { - let checkPink = colourBush.every((berriesPink) => berriesPink === "pink"); - if (checkPink) { - //you can also write if (arr.every(pinkBerries => pinkBerries === "pink")) - return "Bush is safe to eat from"; - } else { - return "Toxic! Leave bush alone!"; +function bushChecker(safeBush) { + if (bushBerryColours1 === "pink") { + console.log("Bush is safe to eat from"); + + } else if (bushBerryColours2 === "pink") { + console.log("Toxic! Leave bush alone!"); + } } From 41ee366aef872ee6e1c3f1aae0c8485e63fe6b40 Mon Sep 17 00:00:00 2001 From: azadaafo Date: Tue, 7 Jul 2020 00:47:16 +0100 Subject: [PATCH 08/11] failed colonisers function --- week-3/Homework/mandatory/3-space-colonies.js | 25 ++----------------- 1 file changed, 2 insertions(+), 23 deletions(-) diff --git a/week-3/Homework/mandatory/3-space-colonies.js b/week-3/Homework/mandatory/3-space-colonies.js index 271276269..844cc2416 100644 --- a/week-3/Homework/mandatory/3-space-colonies.js +++ b/week-3/Homework/mandatory/3-space-colonies.js @@ -13,29 +13,8 @@ */ -function colonisers(families) { - return families.filter( - (checkNames) => - checkNames.charAt(0) === "A" && checkNames.includes("family") - ); -} - -console.log( - colonisers([ - "Adam family", - "Potter family", - "Eric", - "Aldous", - "Button family", - "Jude", - "Carmichael", - "Bunny", - "Asimov", - "Oscar family", - "Avery family", - "Archer family", - ]) -); +function colonisers() { +}; /* ======= TESTS - DO NOT MODIFY ===== */ const voyagers = [ From 0b847a9f4f1ad0a5be0d311719379348ad1f88dc Mon Sep 17 00:00:00 2001 From: azadaafo Date: Tue, 7 Jul 2020 00:58:54 +0100 Subject: [PATCH 09/11] failed eligibility students test --- .../Homework/mandatory/4-eligible-students.js | 52 ++++++++----------- 1 file changed, 21 insertions(+), 31 deletions(-) diff --git a/week-3/Homework/mandatory/4-eligible-students.js b/week-3/Homework/mandatory/4-eligible-students.js index 8a3e1bfad..392f8a53e 100644 --- a/week-3/Homework/mandatory/4-eligible-students.js +++ b/week-3/Homework/mandatory/4-eligible-students.js @@ -53,14 +53,8 @@ console.log(arrayLengths); /* + + + + + + + */ /* Now try the exercise */ -function getEligibleStudents(studentsEligible) { - let studentAttendancyCheck = studentsEligible.filter( - (attendancyCheck) => attendancyCheck[1] >= 8 - ); - let NameOfStudentAttendancyChecked = studentAttendancyCheck.map( - (attendancyCheck) => attendancyCheck[0] - ); - return NameOfStudentAttendancyChecked; +function getEligibleStudents() { + } /* @@ -79,12 +73,8 @@ function getEligibleStudents(studentsEligible) { Hint: To complete the function, search how to change text to lower or upper case by using string method. */ -function getEligibleStudents2(sameNameStudent) { - return sameNameStudent - .filter((checkStudentsNames) => - checkStudentsNames[0].toUpperCase().startsWith("A") - ) - .map((studentWithLetterA) => studentWithLetterA[0]); +function getEligibleStudents2() { + } /* ======= TESTS - DO NOT MODIFY ===== */ @@ -108,26 +98,26 @@ const deltaStudentGroup = [ ] function arraysEqual(a, b) { - if (a === b) return true; - if (a == null || b == null) return false; - if (a.length != b.length) return false; - - for (let i = 0; i < a.length; ++i) { - if (a[i] !== b[i]) return false; - } - - return true; + if (a === b) return true; + if (a == null || b == null) return false; + if (a.length != b.length) return false; + + for (let i = 0; i < a.length; ++i) { + if (a[i] !== b[i]) return false; + } + + return true; } function test(test_name, expr) { - let status; - if (expr) { - status = "PASSED"; - } else { - status = "FAILED"; - } - - console.log(`${test_name}: ${status}`); + let status; + if (expr) { + status = "PASSED"; + } else { + status = "FAILED"; + } + + console.log(`${test_name}: ${status}`); } test("eligibleStudents function works", From 09200ef253d72f4a23f77042a4c6394415db8a04 Mon Sep 17 00:00:00 2001 From: azadaafo Date: Tue, 7 Jul 2020 01:07:10 +0100 Subject: [PATCH 10/11] ha;f task solved --- week-3/Homework/mandatory/5-journey-planner.js | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/week-3/Homework/mandatory/5-journey-planner.js b/week-3/Homework/mandatory/5-journey-planner.js index 521563ba2..eb5fba56a 100644 --- a/week-3/Homework/mandatory/5-journey-planner.js +++ b/week-3/Homework/mandatory/5-journey-planner.js @@ -23,8 +23,7 @@ function checkCodeIsThere(stringText) { let magicWord = "code"; //edit code below - if (stringText.includes(magicWord)) { - // you can also use if(stringText.indexOf(magicWord)>=0) + if (stringText.includes("code")) { return stringText.indexOf(magicWord); } else { return "Not found"; @@ -70,7 +69,7 @@ function checkCodeIsThere(stringText) { Hint: Use the corresponding array method to split the array. */ function getTransportModes(travelDetails) { - return travelDetails.slice(1); // returns last 2 items of the array, does not have the first item + // returns last 2 items of the array, does not have the first item } /* Implement the function isAccessibleByTransportMode that @@ -87,7 +86,7 @@ function getTransportModes(travelDetails) { Hint: Use the corresponding array method to decide if an element is member of an array. */ function isAccessibleByTransportMode(transportModes, transport) { - return transportModes.includes(transport); // returns a boolean value + // returns a boolean value } /* Implement the function getLocationName that @@ -97,7 +96,7 @@ function isAccessibleByTransportMode(transportModes, transport) { e.g: "Tower Bridge" */ function getLocationName(travelDetails) { - return travelDetails[0]; // "Tower Bridge" - student must return this string + // "Tower Bridge" - student must return this string } /* We arrived at the final method. it won't take long if you use the previously implemented functions wisely. @@ -125,14 +124,7 @@ function getLocationName(travelDetails) { */ function journeyPlanner(locations, transportMode) { // Implement the function body - const travelablelocations = locations - .filter((location) => location.includes(transportMode)) // filter correct location details - .map((location) => { - const locationName = location[0]; // grab the string name, which is the first string at the start - return locationName; - }); - - return travelablelocations; + } /* ======= TESTS - DO NOT MODIFY ===== */ From 540a3fdf4d9158fb8f1d569c6fad3badedc93318 Mon Sep 17 00:00:00 2001 From: azadaafo Date: Tue, 7 Jul 2020 01:13:37 +0100 Subject: [PATCH 11/11] failed lane test --- week-3/Homework/mandatory/6-lane-names.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/week-3/Homework/mandatory/6-lane-names.js b/week-3/Homework/mandatory/6-lane-names.js index 360205499..d63c6b775 100644 --- a/week-3/Homework/mandatory/6-lane-names.js +++ b/week-3/Homework/mandatory/6-lane-names.js @@ -6,9 +6,12 @@ */ //hint: string and array methods that could be helpful (indexOf, filter) function getLanes(names) { - const targetName = "Lane"; // string 'Lane' needs to be used - return names.filter((name) => name.includes(targetName)); - } + if (streetNames.includes("Lane")) { + return names; + } +} + + /* ======= TESTS - DO NOT MODIFY ===== */ @@ -24,14 +27,14 @@ function arraysEqual(a, b) { if (a === b) return true; if (a == null || b == null) return false; if (a.length != b.length) return false; - + for (let i = 0; i < a.length; ++i) { - if (a[i] !== b[i]) return false; + if (a[i] !== b[i]) return false; } - + return true; } - + function test(test_name, expr) { let status; if (expr) { @@ -39,7 +42,7 @@ function test(test_name, expr) { } else { status = "FAILED"; } - + console.log(`${test_name}: ${status}`); }