diff --git a/1-exercises/A-array-find/exercise.js b/1-exercises/A-array-find/exercise.js index 35902fed..7711bac3 100644 --- a/1-exercises/A-array-find/exercise.js +++ b/1-exercises/A-array-find/exercise.js @@ -17,9 +17,10 @@ let names = [ "Ahmed", ]; -let longNameThatStartsWithA = findLongNameThatStartsWithA(names); +let longNameThatStartsWithA = names.find(name => name.startsWith("A") && name.length > 7); +console.log(longNameThatStartsWithA); + -console.log(longNameThatStartsWithA); /* EXPECTED OUTPUT */ // "Alexandra" diff --git a/1-exercises/B-array-some/exercise.js b/1-exercises/B-array-some/exercise.js index fddc69ee..48225163 100644 --- a/1-exercises/B-array-some/exercise.js +++ b/1-exercises/B-array-some/exercise.js @@ -15,6 +15,14 @@ let pairsByIndex = [[0, 3], [1, 2], [2, 1], null, [3, 0]]; let students = ["Islam", "Lesley", "Harun", "Rukmini"]; let mentors = ["Daniel", "Irina", "Mozafar", "Luke"]; +function isNull(pair){ + return pair === null; + } + +if(pairsByIndex.some(isNull)){ + process.exit(1); +} + let pairs = pairsByIndex.map(function (indexes) { let student = students[indexes[0]]; let mentor = mentors[indexes[1]]; diff --git a/1-exercises/C-array-every/exercise.js b/1-exercises/C-array-every/exercise.js index 347b9632..128f04fc 100644 --- a/1-exercises/C-array-every/exercise.js +++ b/1-exercises/C-array-every/exercise.js @@ -5,9 +5,8 @@ let students = ["Omar", "Austine", "Dany", "Swathi", "Lesley", "Rukmini"]; let group = ["Austine", "Dany", "Swathi", "Daniel"]; -let groupIsOnlyStudents; // complete this statement - -if (groupIsOnlyStudents) { +let groupIsOnlyStudents = group.every(student => students.includes(student)); // complete this statement +if(groupIsOnlyStudents){ console.log("The group contains only students"); } else { console.log("The group does not contain only students"); diff --git a/1-exercises/D-array-filter/exercise.js b/1-exercises/D-array-filter/exercise.js index 51837028..a3bcd292 100644 --- a/1-exercises/D-array-filter/exercise.js +++ b/1-exercises/D-array-filter/exercise.js @@ -8,11 +8,17 @@ let pairsByIndexRaw = [[0, 3], [1, 2], [2, 1], null, [1], false, "whoops"]; -let pairsByIndex; // Complete this statement let students = ["Islam", "Lesley", "Harun", "Rukmini"]; let mentors = ["Daniel", "Irina", "Mozafar", "Luke"]; +let pairsByIndex = pairsByIndexRaw.filter(function(pair){ + return Array.isArray(pair) && pair.length === 2 && typeof pair[0] === "number" && typeof pair[1] === "number" && pair[0] < students.length && pair[1] < mentors.length; +}); // Complete this statement + +// let students = ["Islam", "Lesley", "Harun", "Rukmini"]; +// let mentors = ["Daniel", "Irina", "Mozafar", "Luke"]; + let pairs = pairsByIndex.map(function (indexes) { let student = students[indexes[0]]; let mentor = mentors[indexes[1]]; diff --git a/1-exercises/E-array-map/exercise.js b/1-exercises/E-array-map/exercise.js index 5a157279..5810761a 100644 --- a/1-exercises/E-array-map/exercise.js +++ b/1-exercises/E-array-map/exercise.js @@ -3,7 +3,9 @@ let numbers = [0.1, 0.2, 0.3, 0.4, 0.5]; -let numbersMultipliedByOneHundred; // complete this statement +let numbersMultipliedByOneHundred = numbers.map(function(numbersMultipliedByOneHundred){ + return numbersMultipliedByOneHundred * 100; +}); // complete this statement console.log(numbersMultipliedByOneHundred); diff --git a/1-exercises/F-array-forEach/exercise.js b/1-exercises/F-array-forEach/exercise.js index 985068cc..ad538bf7 100644 --- a/1-exercises/F-array-forEach/exercise.js +++ b/1-exercises/F-array-forEach/exercise.js @@ -9,6 +9,18 @@ let arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]; +arr.forEach(num => { + if (num % 3 === 0){ + console.log("Fizz"); + } else if(num % 5 === 0){ + console.log("Buzz"); + }else if(num % 3 === 0 && num % 5 === 0) { + console.log("Fizzbuzz"); + } else{ + console.log(num); + } +}); + /* 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/H-array-methods-2/exercise.js b/1-exercises/H-array-methods-2/exercise.js index 59c5daa7..25322276 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, 6); // 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..dd796568 100644 --- a/1-exercises/H-array-methods-2/exercise2.js +++ b/1-exercises/H-array-methods-2/exercise2.js @@ -7,12 +7,30 @@ Tip: use the string method .split() and the array method .join() */ -function capitalise(str) {} +function capitalise(str) { + // return str.charAt(0).toUpperCase() + str.slice(1); + const chars = str.split(""); + console.log(chars[0].join("")); +} + +function capitalise(str) { + // split the string into an array of words + const words = str.split(" "); + + // iterate over each word and capitalise the first letter + const capitalisedWords = words.map((word) => { + return word.charAt(0).toUpperCase() + word.slice(1); + }); + + // join the capitalised words back into a string and return it + return capitalisedWords.join(" "); +} + /* DO NOT EDIT BELOW THIS LINE --------------------------- */ -let name = "daniel"; +const name = "daniel"; console.log(capitalise(name)); console.log(capitalise("hello")); diff --git a/1-exercises/H-array-methods-2/exercise3.js b/1-exercises/H-array-methods-2/exercise3.js index c8e079e4..b3973fb0 100644 --- a/1-exercises/H-array-methods-2/exercise3.js +++ b/1-exercises/H-array-methods-2/exercise3.js @@ -7,8 +7,15 @@ let ukNations = ["Scotland", "Wales", "England", "Northern Ireland"]; function isInUK(country) { - return; // complete this statement + for (let ukNation of ukNations){ + const isInUK = ukNations.includes(country); + return isInUK; + }; // complete this statement } +const isFrance = isInUK("France"); +const isRepublicOfIreland = isInUK("Republic of Ireland"); +const isEngland = isInUK("England"); + /* DO NOT EDIT BELOW THIS LINE diff --git a/1-exercises/I-string-replace/exercise.js b/1-exercises/I-string-replace/exercise.js index 3f7104d7..64b8d63f 100644 --- a/1-exercises/I-string-replace/exercise.js +++ b/1-exercises/I-string-replace/exercise.js @@ -13,7 +13,10 @@ 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", "100000").replace("great", "brilliant"); why not correct + +let result = story.replace(/dogs/g, "cats").replace(/day/g, "night").replace(/10/g, "100000").replace(/great/g, "brilliant"); + /* EXPECTED OUTPUT */ diff --git a/2-mandatory/1-create-functions.js b/2-mandatory/1-create-functions.js index 6df12961..ecd550a9 100644 --- a/2-mandatory/1-create-functions.js +++ b/2-mandatory/1-create-functions.js @@ -3,7 +3,8 @@ 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(array) { + return array.slice(0, 5); } /* @@ -11,7 +12,8 @@ Write a function that: - Accepts an array as a parameter. - Returns a new array containing the same elements, except sorted. */ -function sortArray() { +function sortArray(array) { + return array.some(); } /* diff --git a/2-mandatory/2-oxygen-levels.js b/2-mandatory/2-oxygen-levels.js index 5711c5e5..dca8ef5b 100644 --- a/2-mandatory/2-oxygen-levels.js +++ b/2-mandatory/2-oxygen-levels.js @@ -10,8 +10,12 @@ Some string methods that might help you here are .replace() and .substring(). */ - -function findSafeOxygenLevel() {} +function isSafeOxygenLevel(oxygenLevel){ + return parseFloat(oxygenLevel)>19.5 && parseFloat(oxygenLevel)<23.5; +} +function findSafeOxygenLevel(oxygenLevels) { + return oxygenLevels.find(isSafeOxygenLevel); +} /* ======= TESTS - DO NOT MODIFY ===== */ diff --git a/2-mandatory/3-bush-berries.js b/2-mandatory/3-bush-berries.js index b434a507..8b77cc54 100644 --- a/2-mandatory/3-bush-berries.js +++ b/2-mandatory/3-bush-berries.js @@ -1,3 +1,4 @@ + /* The space travellers have safely landed and are foraging for food in the natural wildlife. @@ -25,6 +26,12 @@ function isBushSafe(berryArray) { //Write your code here } +/*if (isVegetarian) { + return "Macaroni and Cheese"; +} else { + return "Steak and Chips"; +}*/ + /* ======= TESTS - DO NOT MODIFY ===== */ test("isBushSafe finds toxic busy", () => { diff --git a/3-extra/1-card-vailidator.md b/3-extra/1-card-vailidator.md index 65ace5bc..786b9eb0 100644 --- a/3-extra/1-card-vailidator.md +++ b/3-extra/1-card-vailidator.md @@ -34,3 +34,4 @@ These are the requirements your project needs to fulfill: - Use `node` from the command line to test if your code works as expected. Good luck! +