Skip to content
This repository was archived by the owner on Oct 26, 2020. It is now read-only.

Azad week 3 #1019

Open
wants to merge 11 commits into
base: manchester3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 17 additions & 22 deletions week-3/Homework/mandatory/1-oxygen-levels.js
Original file line number Diff line number Diff line change
@@ -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%") {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oxygenLevels1 should have been an input parameter instead of using the global variable from outside.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oxygenLevels1 >= "19.5%" comparison won't work because oxygenLevels1 is an array whereas "19.5%" is a string. Also, you have to parse number form the value of each array element and then compare as a number.

return `oxygen level is safe`
} else {
`oxygen level is not safe`
}
}

/* ======= TESTS - DO NOT MODIFY ===== */
Expand All @@ -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%"
);
11 changes: 8 additions & 3 deletions week-3/Homework/mandatory/2-bush-berries.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you recognised here that you need input, but you haven't used it

if (bushBerryColours1 === "pink") {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, it is a comparison of an array and a string so it doesn't make sense logically.

console.log("Bush is safe to eat from");

function bushChecker() {
} else if (bushBerryColours2 === "pink") {
console.log("Toxic! Leave bush alone!");

}
}

/* ======= TESTS - DO NOT MODIFY ===== */
Expand Down
4 changes: 2 additions & 2 deletions week-3/Homework/mandatory/3-space-colonies.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

*/

function colonisers() {}

function colonisers() {
};
/* ======= TESTS - DO NOT MODIFY ===== */

const voyagers = [
Expand Down
36 changes: 19 additions & 17 deletions week-3/Homework/mandatory/4-eligible-students.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ console.log(arrayLengths);
/* Now try the exercise */

function getEligibleStudents() {

}

/*
Expand All @@ -73,6 +74,7 @@ function getEligibleStudents() {
*/

function getEligibleStudents2() {

}

/* ======= TESTS - DO NOT MODIFY ===== */
Expand All @@ -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",
Expand Down
20 changes: 12 additions & 8 deletions week-3/Homework/mandatory/5-journey-planner.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Expand Down Expand Up @@ -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:
Expand All @@ -84,17 +85,19 @@ 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
e.g:["Tower Bridge", "tube", "river boat"]
- 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.

Expand All @@ -121,6 +124,7 @@ function getLocationName() { }
*/
function journeyPlanner(locations, transportMode) {
// Implement the function body

}

/* ======= TESTS - DO NOT MODIFY ===== */
Expand Down
18 changes: 11 additions & 7 deletions week-3/Homework/mandatory/6-lane-names.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand All @@ -23,22 +27,22 @@ 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) {
status = "PASSED";
} else {
status = "FAILED";
}

console.log(`${test_name}: ${status}`);
}

Expand Down