diff --git a/1-exercises/A-array-find/exercise.js b/1-exercises/A-array-find/exercise.js index 35902fed..998e16a2 100644 --- a/1-exercises/A-array-find/exercise.js +++ b/1-exercises/A-array-find/exercise.js @@ -16,10 +16,16 @@ let names = [ "Karim", "Ahmed", ]; - +/* let longNameThatStartsWithA = findLongNameThatStartsWithA(names); console.log(longNameThatStartsWithA); +const found = names.find(element => element[0] === "A" );*/ + + + +const found = names.find(element => element[0] === "A" && element.length > 7 ); + /* EXPECTED OUTPUT */ // "Alexandra" diff --git a/1-exercises/B-array-some/exercise.js b/1-exercises/B-array-some/exercise.js index fddc69ee..cb64524e 100644 --- a/1-exercises/B-array-some/exercise.js +++ b/1-exercises/B-array-some/exercise.js @@ -6,6 +6,12 @@ - Do not edit any of the existing code */ +for (const pair of pairsByIndex) { + if (!pair) { + process.exit(1); + } +} + 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 diff --git a/1-exercises/C-array-every/exercise.js b/1-exercises/C-array-every/exercise.js index 347b9632..f36c336f 100644 --- a/1-exercises/C-array-every/exercise.js +++ b/1-exercises/C-array-every/exercise.js @@ -5,7 +5,13 @@ let students = ["Omar", "Austine", "Dany", "Swathi", "Lesley", "Rukmini"]; let group = ["Austine", "Dany", "Swathi", "Daniel"]; -let groupIsOnlyStudents; // complete this statement +let groupIsOnlyStudents = function () { + for (let i = 0; i < students.length; i++) { + if (!group.includes(student[i])) { + return true; + } + } +}; // complete this statement 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..bd613343 100644 --- a/1-exercises/D-array-filter/exercise.js +++ b/1-exercises/D-array-filter/exercise.js @@ -8,7 +8,9 @@ let pairsByIndexRaw = [[0, 3], [1, 2], [2, 1], null, [1], false, "whoops"]; -let pairsByIndex; // Complete this statement +let pairsByIndex = pairsByIndexRaw.filter(function (item) { + return Array.isArray(item) && item.length === 2; +}); // Complete this statement let students = ["Islam", "Lesley", "Harun", "Rukmini"]; let mentors = ["Daniel", "Irina", "Mozafar", "Luke"]; @@ -24,4 +26,4 @@ console.log(pairs); /* EXPECTED RESULT [ [ 'Islam', 'Luke' ], [ 'Lesley', 'Mozafar' ], [ 'Harun', 'Irina' ] ] -*/ \ No newline at end of file +*/ diff --git a/1-exercises/E-array-map/exercise.js b/1-exercises/E-array-map/exercise.js index 5a157279..dd28253a 100644 --- a/1-exercises/E-array-map/exercise.js +++ b/1-exercises/E-array-map/exercise.js @@ -3,11 +3,11 @@ let numbers = [0.1, 0.2, 0.3, 0.4, 0.5]; -let numbersMultipliedByOneHundred; // complete this statement +let numbersMultipliedByOneHundred = numbers.map((element) => element * 100); // complete this statement console.log(numbersMultipliedByOneHundred); /* EXPECTED RESULT [10, 20, 30, 40, 50] -*/ \ No newline at end of file +*/ diff --git a/1-exercises/F-array-forEach/exercise.js b/1-exercises/F-array-forEach/exercise.js index 985068cc..6fb63357 100644 --- a/1-exercises/F-array-forEach/exercise.js +++ b/1-exercises/F-array-forEach/exercise.js @@ -9,6 +9,19 @@ let arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]; +arr.forEach((number) => { + if (number % 3 === 0 && number % 5 === 0) { + console.log("FizzBuzz"); + } else if (number % 3 === 0) { + console.log("Fizz"); + } else if (number % 5 === 0) { + console.log("Buzz"); + } else { + console.log(number); + } +}); + +console.log(filteredNumbers); /* 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..d49597b6 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 = mentor.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..45fd2c5e 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(-5); // 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..99b8823e 100644 --- a/1-exercises/H-array-methods-2/exercise2.js +++ b/1-exercises/H-array-methods-2/exercise2.js @@ -7,7 +7,13 @@ Tip: use the string method .split() and the array method .join() */ -function capitalise(str) {} +function capitalise(str) { + let strString = str.split("") + let strFirst = strString[0].toUpperCase() + let strCombined = strFirst.concat(str.slice(1)) + return strCombined + +} /* 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..6a832239 100644 --- a/1-exercises/H-array-methods-2/exercise3.js +++ b/1-exercises/H-array-methods-2/exercise3.js @@ -7,7 +7,12 @@ let ukNations = ["Scotland", "Wales", "England", "Northern Ireland"]; function isInUK(country) { - return; // complete this statement +if (ukNations.includes(country)){ +return true +} + else{ + return "Not a UK country" + } } /* diff --git a/1-exercises/J-string-substring/exercise.js b/1-exercises/J-string-substring/exercise.js index 4624db68..35c09931 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(0,18); console.log(statement); diff --git a/1-exercises/J-string-substring/exercise2.js b/1-exercises/J-string-substring/exercise2.js index a1d9bf62..8a70eace 100644 --- a/1-exercises/J-string-substring/exercise2.js +++ b/1-exercises/J-string-substring/exercise2.js @@ -24,6 +24,28 @@ names.forEach((name) => { console.log(name); }); +/*Other function j + +function getFirstNames (){ +let splitNames =[] +for(let i =0; i 3){ +arrE.push('100%') +} +else{ +arrE.push(num) +} + + + } + +formatPercentage([1,2,1000,5,6,34])*/ + +function formatPercentage(arr) { + let result = []; + for (const number of arr) { + if (number > 100) { + result.push('100%') + } else { + result.push(`${Number(number.toFixed(2))}%`) + } + } + return result; } /* ======= TESTS - DO NOT MODIFY ===== */ diff --git a/2-mandatory/2-oxygen-levels.js b/2-mandatory/2-oxygen-levels.js index 5711c5e5..1210312c 100644 --- a/2-mandatory/2-oxygen-levels.js +++ b/2-mandatory/2-oxygen-levels.js @@ -11,7 +11,21 @@ Some string methods that might help you here are .replace() and .substring(). */ -function findSafeOxygenLevel() {} +function findSafeOxygenLevel() { + let firstProperPlanet = "" ; + for (const oxygenlevel of oxygenLevels) { + if(oxygenlevel.includes('%')) { + const oxygenlevelNum = Number(oxygenlevel.replace('%', '')); + if (oxygenlevelNum > 19.5 && oxygenlevelNum < 23.5){ + firstProperPlanet = oxygenlevel; + break + }} else { + continue + } + } + let output = firstProperPlanet === "" ? undefined : firstProperPlanet; + return output; +} /* ======= TESTS - DO NOT MODIFY ===== */ diff --git a/2-mandatory/3-bush-berries.js b/2-mandatory/3-bush-berries.js index b434a507..aa4b2068 100644 --- a/2-mandatory/3-bush-berries.js +++ b/2-mandatory/3-bush-berries.js @@ -22,9 +22,20 @@ */ function isBushSafe(berryArray) { + if (berryArray.every() == "pink") { + return "Bush is safe to eat"; + } else { + return "Toxic! Leave bush alone!"; + } //Write your code here } +const bushIsSafe = berryArray.every((color) => color == "pink"); +const output = bushIsSafe + ? "Bush is safe to eat from" + : "Toxic! Leave bush alone!"; +return output; + /* ======= TESTS - DO NOT MODIFY ===== */ test("isBushSafe finds toxic busy", () => { diff --git a/2-mandatory/4-space-colonies.js b/2-mandatory/4-space-colonies.js index 30095213..128b7dae 100644 --- a/2-mandatory/4-space-colonies.js +++ b/2-mandatory/4-space-colonies.js @@ -15,7 +15,9 @@ */ -function getSettlers() {} +function getSettlers() { + return allpeople.filter(person => person.includes('family') && person.startsWith('A')); +} /* ======= TESTS - DO NOT MODIFY ===== */ diff --git a/2-mandatory/5-eligible-students.js b/2-mandatory/5-eligible-students.js index f92478e0..0d5825e8 100644 --- a/2-mandatory/5-eligible-students.js +++ b/2-mandatory/5-eligible-students.js @@ -7,7 +7,12 @@ - Returns an array containing only the names of the who have attended AT LEAST 8 classes */ -function getEligibleStudents() {} +function getEligibleStudents() { + let examClass = []; + for (student in attendance){ + if student[1] + } +} /* ======= TESTS - DO NOT MODIFY ===== */ diff --git a/2-mandatory/6-journey-planner.js b/2-mandatory/6-journey-planner.js index 25a14083..4b13d761 100644 --- a/2-mandatory/6-journey-planner.js +++ b/2-mandatory/6-journey-planner.js @@ -20,7 +20,7 @@ function checkCodeIsThere(stringText) { let magicWord = "code"; //edit code below - if (stringText) { + if (stringText.includes("code")) { return stringText; } else { return "Not found"; @@ -64,7 +64,9 @@ function checkCodeIsThere(stringText) { Hint: Use the corresponding array method to split the array. */ -function getTransportModes() {} +function getTransportModes(arr) { + return arr.splice(1) +} /* Implement the function isAccessibleByTransportMode that @@ -81,7 +83,12 @@ function getTransportModes() {} Hint: Use the corresponding array method to decide if an element is included in an array. */ -function isAccessibleByTransportMode() {} +function isAccessibleByTransportMode(arr, transport) { +if (arr.includes(transport)){ +console.log(true) +}else{console.log(false)} +} + /* Implement the function getLocationName that @@ -92,7 +99,9 @@ function isAccessibleByTransportMode() {} - Returns the name of the location e.g: "Tower Bridge" */ -function getLocationName() {} +function getLocationName(arr) { + return arr[0] +} /* We arrived at the final method. it won't take long if you use the previously implemented functions wisely.