diff --git a/week-3/Homework/mandatory/1-oxygen-levels.js b/week-3/Homework/mandatory/1-oxygen-levels.js index a105fdeb8..16ed5bc23 100644 --- a/week-3/Homework/mandatory/1-oxygen-levels.js +++ b/week-3/Homework/mandatory/1-oxygen-levels.js @@ -1,34 +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() { - + if (oxygenLevels1 >= "19.5%" && oxygenLevels1 <= "23.5%") { + return `oxygen level is safe` + } else { + `oxygen level is not safe` + } } /* ======= TESTS - DO NOT MODIFY ===== */ @@ -37,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 diff --git a/week-3/Homework/mandatory/2-bush-berries.js b/week-3/Homework/mandatory/2-bush-berries.js index ea5118004..9b461b34d 100644 --- a/week-3/Homework/mandatory/2-bush-berries.js +++ b/week-3/Homework/mandatory/2-bush-berries.js @@ -18,18 +18,23 @@ 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(safeBush) { + if (bushBerryColours1 === "pink") { + console.log("Bush is safe to eat from"); -function bushChecker() { + } else if (bushBerryColours2 === "pink") { + console.log("Toxic! Leave bush alone!"); + } } /* ======= TESTS - DO NOT MODIFY ===== */ diff --git a/week-3/Homework/mandatory/3-space-colonies.js b/week-3/Homework/mandatory/3-space-colonies.js index f9e7ba636..844cc2416 100644 --- a/week-3/Homework/mandatory/3-space-colonies.js +++ b/week-3/Homework/mandatory/3-space-colonies.js @@ -13,8 +13,8 @@ */ -function colonisers() {} - +function colonisers() { +}; /* ======= TESTS - DO NOT MODIFY ===== */ const voyagers = [ diff --git a/week-3/Homework/mandatory/4-eligible-students.js b/week-3/Homework/mandatory/4-eligible-students.js index e72ddedb1..392f8a53e 100644 --- a/week-3/Homework/mandatory/4-eligible-students.js +++ b/week-3/Homework/mandatory/4-eligible-students.js @@ -54,6 +54,7 @@ console.log(arrayLengths); /* Now try the exercise */ function getEligibleStudents() { + } /* @@ -73,6 +74,7 @@ function getEligibleStudents() { */ function getEligibleStudents2() { + } /* ======= TESTS - DO NOT MODIFY ===== */ @@ -96,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", diff --git a/week-3/Homework/mandatory/5-journey-planner.js b/week-3/Homework/mandatory/5-journey-planner.js index 0ac48b8cd..eb5fba56a 100644 --- a/week-3/Homework/mandatory/5-journey-planner.js +++ b/week-3/Homework/mandatory/5-journey-planner.js @@ -23,8 +23,8 @@ function checkCodeIsThere(stringText) { let magicWord = "code"; //edit code below - if (stringText) { - return stringText; + if (stringText.includes("code")) { + return stringText.indexOf(magicWord); } else { return "Not found"; } @@ -68,8 +68,9 @@ function checkCodeIsThere(stringText) { Hint: Use the corresponding array method to split the array. */ -function getTransportModes() { } - +function getTransportModes(travelDetails) { + // returns last 2 items of the array, does not have the first item +} /* Implement the function isAccessibleByTransportMode that - Accepts two parameters: @@ -84,8 +85,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) { + // returns a boolean value +} /* Implement the function getLocationName that - Accepts a location and available transports in an array @@ -93,8 +95,9 @@ function isAccessibleByTransportMode() { } - Returns the name of the location e.g: "Tower Bridge" */ -function getLocationName() { } - +function getLocationName(travelDetails) { + // "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 +124,7 @@ function getLocationName() { } */ function journeyPlanner(locations, transportMode) { // Implement the function body + } /* ======= TESTS - DO NOT MODIFY ===== */ diff --git a/week-3/Homework/mandatory/6-lane-names.js b/week-3/Homework/mandatory/6-lane-names.js index caf88c4ca..d63c6b775 100644 --- a/week-3/Homework/mandatory/6-lane-names.js +++ b/week-3/Homework/mandatory/6-lane-names.js @@ -5,10 +5,14 @@ */ //hint: string and array methods that could be helpful (indexOf, filter) -function getLanes() { - +function getLanes(names) { + if (streetNames.includes("Lane")) { + return names; + } } + + /* ======= TESTS - DO NOT MODIFY ===== */ const streetNames = [ @@ -23,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) { @@ -38,7 +42,7 @@ function test(test_name, expr) { } else { status = "FAILED"; } - + console.log(`${test_name}: ${status}`); }