diff --git a/.DS_Store b/.DS_Store index 4cb80315b..49ac4c4ed 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 000000000..822e5d1e3 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,17 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "node", + "request": "launch", + "name": "Launch Program", + "skipFiles": [ + "/**" + ], + "program": "${file}" + } + ] +} \ No newline at end of file diff --git a/week-1/Homework/extra/1-currency-conversion.js b/week-1/Homework/extra/1-currency-conversion.js index f96ea2e8a..f32fd4e97 100644 --- a/week-1/Homework/extra/1-currency-conversion.js +++ b/week-1/Homework/extra/1-currency-conversion.js @@ -5,7 +5,10 @@ Write a function that converts a price to USD (exchange rate is 1.4 $ to £) */ -function convertToUSD() {} +function convertToUSD(priceGBP) { + let priceUSD = priceGBP * 1.4; + return priceUSD; +} /* CURRENCY FORMATTING @@ -16,20 +19,23 @@ function convertToUSD() {} Find a way to add 1% to all currency conversions (think about the DRY principle) */ -function convertToBRL() {} +function convertToBRL(priceGBP) { + let priceBRL = priceGBP * 5.7 * 1.01; + return priceBRL; +} /* ======= TESTS - DO NOT MODIFY ===== */ function test(test_name, expr) { let status; if (expr) { - status = "PASSED" + status = "PASSED"; } else { - status = "FAILED" + status = "FAILED"; } - console.log(`${test_name}: ${status}`) + console.log(`${test_name}: ${status}`); } -test('convertToUSD function works', convertToUSD(32) === 44.8) -test('convertToBRL function works', convertToBRL(30) === 172.71) +test("convertToUSD function works", convertToUSD(32) === 44.8); +test("convertToBRL function works", convertToBRL(30) === 172.71); diff --git a/week-1/Homework/extra/2-piping.js b/week-1/Homework/extra/2-piping.js index 5f5ea4e5b..56a238c63 100644 --- a/week-1/Homework/extra/2-piping.js +++ b/week-1/Homework/extra/2-piping.js @@ -15,44 +15,49 @@ 3. Write a more readable version of what you wrote in step 2 under the BETTER PRACTICE comment. Assign the final result to the variable goodCode */ - -function add() { - +let a, b, c, d; +function add(a, b) { + let summa = Math.round((a + b) * 10) / 10; + return summa; } -function multiply() { - +function multiply(b, c) { + return b * c; } -function format() { - +function format(d) { + return "£" + d; } - -const startingValue = 2 +console.log(add(1, 3)); +console.log(add(2.4, 5.3)); +const startingValue = 2; // Why can this code be seen as bad practice? Comment your answer. -let badCode = + +let badCode = format(multiply(add(10, startingValue), 2)); /* BETTER PRACTICE */ -let goodCode = +addValue = add(startingValue, 10); +multiplayValue = multiply(addValue, 2); +let goodCode = format(multiplayValue); /* ======= TESTS - DO NOT MODIFY ===== */ function test(test_name, expr) { let status; if (expr) { - status = "PASSED" + status = "PASSED"; } else { - status = "FAILED" + status = "FAILED"; } - console.log(`${test_name}: ${status}`) + console.log(`${test_name}: ${status}`); } -test('add function - case 1 works', add(1,3) === 4) -test('add function - case 2 works', add(2.4,5.3) === 7.7) -test('multiply function works', multiply(2,3) === 6) -test('format function works', format(16) === "£16") -test('badCode variable correctly assigned', badCode === "£24") -test('goodCode variable correctly assigned', goodCode === "£24") \ No newline at end of file +test("add function - case 1 works", add(1, 3) === 4); +test("add function - case 2 works", add(2.4, 5.3) === 7.7); +test("multiply function works", multiply(2, 3) === 6); +test("format function works", format(16) === "£16"); +test("badCode variable correctly assigned", badCode === "£24"); +test("goodCode variable correctly assigned", goodCode === "£24"); diff --git a/week-1/Homework/mandatory/1-syntax-errors.js b/week-1/Homework/mandatory/1-syntax-errors.js index b32f8a34c..5787894f7 100644 --- a/week-1/Homework/mandatory/1-syntax-errors.js +++ b/week-1/Homework/mandatory/1-syntax-errors.js @@ -1,32 +1,39 @@ // There are syntax errors in this code - can you fix it to pass the tests? -function addNumbers(a b c) { - return a + b + c; +function addNumbers(a, b, c) { + return a + b + c; } -function introduceMe(name, age) -return "Hello, my name is " + name "and I am " age + "years old"; - +function introduceMe(name, age) { + return "Hello, my name is " + name + " and I am " + age + " years old"; +} function getRemainder(a, b) { - remainder = a %% b; + remainder = a % b; - // Use string interpolation here - return "The remainder is %{remainder}" + // Use string interpolation here + return `The remainder is ${remainder}`; } /* ======= TESTS - DO NOT MODIFY ===== */ 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("fixed addNumbers function - case 1", addNumbers(3,4,6) === 13) -test("fixed introduceMe function", introduceMe("Sonjide",27) === "Hello, my name is Sonjide and I am 27 years old") -test("fixed getRemainder function", getRemainder(23,5) === "The remainder is 3") +test("fixed addNumbers function - case 1", addNumbers(3, 4, 6) === 13); +test( + "fixed introduceMe function", + introduceMe("Sonjide", 27) === + "Hello, my name is Sonjide and I am 27 years old" +); +test( + "fixed getRemainder function", + getRemainder(23, 5) === "The remainder is 3" +); diff --git a/week-1/Homework/mandatory/2-logic-error.js b/week-1/Homework/mandatory/2-logic-error.js index e040e106a..4ea7d4b25 100644 --- a/week-1/Homework/mandatory/2-logic-error.js +++ b/week-1/Homework/mandatory/2-logic-error.js @@ -1,16 +1,15 @@ // The syntax for this function is valid but it has an error, find it and fix it. function trimWord(word) { - return wordtrim(); + return word.trim(); } function getWordLength(word) { - return "word".length() + return word.length; } function multiply(a, b, c) { - a * b * c; - return; + return a * b * c; } /* ======= TESTS - DO NOT MODIFY ===== */ @@ -18,14 +17,20 @@ function multiply(a, b, c) { function test(test_name, expr) { let status; if (expr) { - status = "PASSED" + status = "PASSED"; } else { - status = "FAILED" + status = "FAILED"; } - console.log(`${test_name}: ${status}`) + console.log(`${test_name}: ${status}`); } -test("fixed trimWord function", trimWord(" CodeYourFuture ") === "CodeYourFuture") -test("fixed wordLength function", getWordLength("A wild sentence appeared!") === 25) -test("fixed multiply function", multiply(2,3,6) === 36) \ No newline at end of file +test( + "fixed trimWord function", + trimWord(" CodeYourFuture ") === "CodeYourFuture" +); +test( + "fixed wordLength function", + getWordLength("A wild sentence appeared!") === 25 +); +test("fixed multiply function", multiply(2, 3, 6) === 36); diff --git a/week-1/Homework/mandatory/3-function-output.js b/week-1/Homework/mandatory/3-function-output.js index a57e4aeca..d61f63d79 100644 --- a/week-1/Homework/mandatory/3-function-output.js +++ b/week-1/Homework/mandatory/3-function-output.js @@ -1,31 +1,39 @@ -// Add comments to explain what this function does. You're meant to use Google! +// The function returns pseudorandom number from [0,10) function getNumber() { - return Math.random() * 10; + return Math.random() * 10; } -// Add comments to explain what this function does. You're meant to use Google! +// The function concatenates 2 words together function s(w1, w2) { - return w1.concat(w2); + return w1.concat(w2); } function concatenate(firstWord, secondWord, thirdWord) { - // Write the body of this function to concatenate three words together - // Look at the test case below to understand what to expect in return + // Write the body of this function to concatenate three words together + // Look at the test case below to understand what to expect in return + return firstWord.concat(" ", secondWord, " ", thirdWord); } - /* ======= TESTS - DO NOT MODIFY ===== */ - 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("concatenate function - case 1 works", concatenate('code', 'your', 'future') === "code your future") -test("concatenate function - case 2 works", concatenate('I', 'like', 'pizza') === "I like pizza") -test("concatenate function - case 3 works", concatenate('I', 'am', 13) === "I am 13") \ No newline at end of file + +test( + "concatenate function - case 1 works", + concatenate("code", "your", "future") === "code your future" +); +test( + "concatenate function - case 2 works", + concatenate("I", "like", "pizza") === "I like pizza" +); +test( + "concatenate function - case 3 works", + concatenate("I", "am", 13) === "I am 13" +); diff --git a/week-1/Homework/mandatory/4-tax.js b/week-1/Homework/mandatory/4-tax.js index 8ddbddad3..b5156d914 100644 --- a/week-1/Homework/mandatory/4-tax.js +++ b/week-1/Homework/mandatory/4-tax.js @@ -5,7 +5,10 @@ Sales tax is 20% of the price of the product */ -function calculateSalesTax() {} +function calculateSalesTax(cost) { + let salesTax = (cost * (100 + 20)) / 100; + return salesTax; +} /* CURRENCY FORMATTING @@ -17,25 +20,36 @@ function calculateSalesTax() {} Remember that the prices must include the sales tax (hint: you already wrote a function for this!) */ -function formatCurrency() {} - +function formatCurrency(cost) { + let twoDecimalSalexTax = calculateSalesTax(cost).toFixed(2); + return "£".concat(twoDecimalSalexTax); +} /* ======= TESTS - DO NOT MODIFY ===== */ function test(test_name, expr) { let status; if (expr) { - status = "PASSED" + status = "PASSED"; } else { - status = "FAILED" + status = "FAILED"; } - console.log(`${test_name}: ${status}`) + console.log(`${test_name}: ${status}`); } -test("calculateSalesTax function - case 1 works", calculateSalesTax(15) === 18) -test("calculateSalesTax function - case 2 works", calculateSalesTax(17.5) === 21) -test("calculateSalesTax function - case 3 works", calculateSalesTax(34) === 40.8) - -test("formatCurrency function - case 1 works", formatCurrency(15) === "£18.00") -test("formatCurrency function - case 2 works", formatCurrency(17.5) === "£21.00") -test("formatCurrency function - case 3 works", formatCurrency(34) === "£40.80") \ No newline at end of file +test("calculateSalesTax function - case 1 works", calculateSalesTax(15) === 18); +test( + "calculateSalesTax function - case 2 works", + calculateSalesTax(17.5) === 21 +); +test( + "calculateSalesTax function - case 3 works", + calculateSalesTax(34) === 40.8 +); + +test("formatCurrency function - case 1 works", formatCurrency(15) === "£18.00"); +test( + "formatCurrency function - case 2 works", + formatCurrency(17.5) === "£21.00" +); +test("formatCurrency function - case 3 works", formatCurrency(34) === "£40.80"); diff --git a/week-1/Homework/mandatory/5-magic-8-ball.js b/week-1/Homework/mandatory/5-magic-8-ball.js index 688552429..8923bcd85 100644 --- a/week-1/Homework/mandatory/5-magic-8-ball.js +++ b/week-1/Homework/mandatory/5-magic-8-ball.js @@ -42,10 +42,35 @@ My sources say no. Outlook not so good. Very doubtful. */ - +const arrayAnswers = [ + "It is certain.", + "It is decidedly so.", + "Without a doubt.", + "Yes - definitely.", + "You may rely on it.]", + "As I see it, yes.", + "Most likely.", + "Outlook good.", + "Yes.", + "Signs point to yes.", + "Reply hazy, try again.", + "Ask again later.", + "Better not tell you now.", + "Cannot predict now.", + "Concentrate and ask again.", + "Don't count on it.", + "My reply is no.", + "My sources say no.", + "Outlook not so good.", + "Very doubtful.", +]; // This should log "The ball has shaken!" // and return the answer. -function shakeBall() {} +function shakeBall() { + console.log("The ball has shaken!"); + variantAnswer = Math.round(Math.random() * 20); + return arrayAnswers[variantAnswer]; +} // The answer should come from shaking the ball let answer; @@ -55,12 +80,21 @@ let answer; // - positive // - negative // - very negative -function checkAnswer() {} +function checkAnswer(answer) { + let typeAnswer; + answer = shakeBall(); + let index = arrayAnswers.indexOf(answer); + if (index <= 4) typeAnswer = "very positive"; + else if (index <= 9) typeAnswer = "positive"; + else if (index <= 14) typeAnswer = "negative"; + else if (index <= 19) typeAnswer = "very negative"; + return typeAnswer; +} /* ======= TESTS - DO NOT MODIFY ===== */ const log = console.log; let logged; -console.log = function() { +console.log = function () { log(...arguments); logged = arguments[0]; }; diff --git a/week-2/.archive/K-array-methods/README.md b/week-2/.archive/K-array-methods/README.md deleted file mode 100644 index cc568c23b..000000000 --- a/week-2/.archive/K-array-methods/README.md +++ /dev/null @@ -1,55 +0,0 @@ -Do you remember how strings have special functions called methods? Don't worry if not! Here's an example to jog your memory: - -```sh -$ node -> var name = "Daniel" -undefined -> name.toLowerCase() -daniel -``` - -Arrays also have several methods that you can use. - -### `.sort()` - -_An array method that sorts the values in an array into ascending alphabetical or numerical order._ - -```js -var unorderedLetters = ["z", "v", "b", "f", "g"]; -var orderedLetters = unorderedLetters.sort(); - -var unorderedNumbers = [8, 5, 1, 4, 2]; -var orderedNumbers = unorderedNumbers.sort(); - -console.log(orderedLetters); // logs [ 'b', 'f', 'g', 'v', 'z' ] -console.log(unorderedLetters); // logs [ 'b', 'f', 'g', 'v', 'z' ] -console.log(orderedNumbers); // logs [ 1, 2, 4, 5, 8 ] -console.log(unorderedNumbers); // logs [ 1, 2, 4, 5, 8 ] -``` - -> When you call this array method it uses the array on the left side of the dot as an input, and it sorts that array also returning it. Note how both ordered and unordered arrays are sorted now! - -### `.concat()` - -_Adds (or concatenates) another value or array to the array._ - -```sh -$ node -> var arr = [1, 2, 3] -undefined -> arr.concat(4) -[1, 2, 3, 4] -> arr -[1, 2, 3] -``` - -Did you notice how calling the concat method did not change `arr`? This is because `concat`, like most array methods, returns a _new_ array, it does not alter the one you called the method on. - -If you wan to use the array returned by calling `.concat()` you should store it in a new variable. - -```js -var arr = [1, 2, 3]; -var newArr = arr.concat(4); - -console.log(newArr); // logs [1, 2, 3, 4] -``` diff --git a/week-2/.archive/K-array-methods/exercise.js b/week-2/.archive/K-array-methods/exercise.js deleted file mode 100644 index 44e9c8012..000000000 --- a/week-2/.archive/K-array-methods/exercise.js +++ /dev/null @@ -1,19 +0,0 @@ -/* - Array methods - sort - -------------------- -*/ - -var numbers = [3, 2, 1]; -var sortedNumbers; // complete this statement - -/* - DO NOT EDIT BELOW THIS LINE - --------------------------- */ - -console.log(sortedNumbers); - -/* - EXPECTED RESULT - --------------- - [1, 2, 3] -*/ diff --git a/week-2/.archive/K-array-methods/exercise2.js b/week-2/.archive/K-array-methods/exercise2.js deleted file mode 100644 index 3dd24a17a..000000000 --- a/week-2/.archive/K-array-methods/exercise2.js +++ /dev/null @@ -1,22 +0,0 @@ -/* - Array methods - concat - ---------------------- - The variable everyone should be an array containing both mentors and students. -*/ - -var mentors = ["Daniel", "Irina", "Rares"]; -var students = ["Rukmini", "Abdul", "Austine", "Swathi"]; - -var everyone; // complete this statement - -/* - DO NOT EDIT BELOW THIS LINE - --------------------------- */ - -console.log(everyone); - -/* - EXPECTED RESULT - --------------- - ["Daniel", "Irina", "Rares", "Rukmini", "Abdul", "Austine", "Swathi"] -*/ diff --git a/week-2/.archive/L-array-methods-2/README.md b/week-2/.archive/L-array-methods-2/README.md deleted file mode 100644 index 507de3192..000000000 --- a/week-2/.archive/L-array-methods-2/README.md +++ /dev/null @@ -1,46 +0,0 @@ -Let's explore some more array methods. - -### `.slice()` - -_Returns a slice of the array._ - -You can tell `.slice()` where you want the slice to begin and end by passing it two parameters. - -```sh -$ node -> var arr = [0, 1, 2, 3, 4] -undefined -> arr.slice(0, 2) -[0, 1] -> ["a", "b", "c", "d"].slice(1, 2) -['b'] -``` - -### `.includes()` - -_Returns true if a value is in the array._ - -```js -var mentors = ["Daniel", "Irini", "Ashleigh", "Rob", "Etzali"]; - -function isAMentor(name) { - return mentors.includes(name); -} - -consooe.log("Is Rukmuni a mentor?"); -console.log(isAMentor("Rukmini")); // logs false -``` - -### `.join()` - -_Returns all the array values joined together in a string. By default, this method takes no parameters and then the elements are divided with a comma `,`. If you provide it with a string parameter though, then it becomes the divider of the elements, like the example below:_ - -```sh -$ node -> ["H", "e", "l", "l", "o"].join(); -'H,e,l,l,o' -> ["H", "e", "l", "l", "o"].join("--"); -'H--e--l--l--o' -``` - -There is a string method `.split()`. In an interactive console try using the string `.split()` method and the array `.join()`. How could they work together? diff --git a/week-2/.archive/L-array-methods-2/exercise.js b/week-2/.archive/L-array-methods-2/exercise.js deleted file mode 100644 index d36303b84..000000000 --- a/week-2/.archive/L-array-methods-2/exercise.js +++ /dev/null @@ -1,33 +0,0 @@ -/* - Array methods - .slice() - ------------------------ - The variable `firstFive` should contain the first five items of `everyone` - The variable `lastFive` should contain the last five items of `everyone` -*/ - -var everyone = [ - "Daniel", - "Irina", - "Rares", - "Rukmini", - "Abdul", - "Austine", - "Swathi" -]; - -var firstFive; // complete this statement -var lastFive; // complete this statement - -/* - DO NOT EDIT BELOW THIS LINE - --------------------------- */ - -console.log(firstFive); -console.log(lastFive); - -/* - EXPECTED RESULT - --------------- - ["Daniel", "Irina", "Rares", "Rukmini", "Abdul"] - ["Rares", "Rukmini", "Abdul", "Austine", "Swathi"] -*/ diff --git a/week-2/.archive/L-array-methods-2/exercise2.js b/week-2/.archive/L-array-methods-2/exercise2.js deleted file mode 100644 index b7be576e7..000000000 --- a/week-2/.archive/L-array-methods-2/exercise2.js +++ /dev/null @@ -1,25 +0,0 @@ -/* - Array methods - .join() - ------------------------- - Complete the capitalise function - It should return a string with the first letter in uppercase - For example, capitailise("hello") should return "Hello" - Tip: use the string method .split() and the array method .join() -*/ - -function capitalise(str) {} - -/* - DO NOT EDIT BELOW THIS LINE - --------------------------- */ -var name = "daniel"; - -console.log(capitalise(name)); -console.log(capitalise("hello")); - -/* - EXPECTED RESULT - --------------- - Daniel - Hello -*/ diff --git a/week-2/.archive/L-array-methods-2/exercise3.js b/week-2/.archive/L-array-methods-2/exercise3.js deleted file mode 100644 index 82e9dd8c8..000000000 --- a/week-2/.archive/L-array-methods-2/exercise3.js +++ /dev/null @@ -1,26 +0,0 @@ -/* - Array methods - .includes() - --------------------------- - Complete the function below to check if a country is in the UK -*/ - -var ukNations = ["Scotland", "Wales", "England", "Northern Ireland"]; - -function isInUK(country) { - return; // complete this statement -} - -/* - DO NOT EDIT BELOW THIS LINE - --------------------------- */ -console.log(isInUK("France")); -console.log(isInUK("Republic of Ireland")); -console.log(isInUK("England")); - -/* - EXPECTED RESULT - --------------- - false - false - true -*/ diff --git a/week-2/.archive/M-array-map/README.md b/week-2/.archive/M-array-map/README.md deleted file mode 100644 index 76ef865e2..000000000 --- a/week-2/.archive/M-array-map/README.md +++ /dev/null @@ -1,27 +0,0 @@ -Imagine you have an array of names... - -```js -var mentors = ["Daniel ", "irina ", " Gordon", "ashleigh "]; -``` - -You notice that he names are not formatted consistently. To fix the array you decide you need to trim whitespace and convert to lowercase. How do you do that for every value in the array? - -We can write a function that changes one name: - -```js -function tidy(name) { - return name.trim().toLowerCase(); -} -``` - -All you need to run every name in the array through this function and update the array values. Thankfully there is an array method that does just this! - -## `.map()` - -_Runs every item in the array through a function and returns a new array with the values returned by the function_. - -```js -var tidyMentors = mentors.map(tidy); - -console.log(tidyMentors); // logs ["daniel", "irina", "gordon", "ashleigh"] -``` diff --git a/week-2/.archive/M-array-map/exercise.js b/week-2/.archive/M-array-map/exercise.js deleted file mode 100644 index 783e8386c..000000000 --- a/week-2/.archive/M-array-map/exercise.js +++ /dev/null @@ -1,24 +0,0 @@ -/* - Array methods - .map() - ------------------------- - `numbersDoubled` should be an array containing all every value in `numbers` doubled - Use the .map() method to transform each item in the array -*/ - -function double(num) { - return num * 2; -} - -var numbers = [1, 2, 3, 4]; -var numbersDoubled; // complete this statement (use map and the double function) - -/* - DO NOT EDIT BELOW THIS LINE - --------------------------- */ -console.log(numbersDoubled); - -/* - EXPECTED RESULT - --------------- - [2,4,6,8] -*/ diff --git a/week-2/Homework/README.md b/week-2/.archive/README.md similarity index 100% rename from week-2/Homework/README.md rename to week-2/.archive/README.md diff --git a/week-2/Homework/extra/4-radio-stations.js b/week-2/.archive/extra/4-radio-stations.js similarity index 100% rename from week-2/Homework/extra/4-radio-stations.js rename to week-2/.archive/extra/4-radio-stations.js diff --git a/week-2/Homework/mandatory/0-freecodecamp.md b/week-2/.archive/mandatory/0-freecodecamp.md similarity index 100% rename from week-2/Homework/mandatory/0-freecodecamp.md rename to week-2/.archive/mandatory/0-freecodecamp.md diff --git a/week-2/Homework/mandatory/1-fix-functions.js b/week-2/.archive/mandatory/1-fix-functions.js similarity index 100% rename from week-2/Homework/mandatory/1-fix-functions.js rename to week-2/.archive/mandatory/1-fix-functions.js diff --git a/week-2/Homework/mandatory/2-function-creation.js b/week-2/.archive/mandatory/2-function-creation.js similarity index 100% rename from week-2/Homework/mandatory/2-function-creation.js rename to week-2/.archive/mandatory/2-function-creation.js diff --git a/week-2/Homework/mandatory/3-playing-computer.js b/week-2/.archive/mandatory/3-playing-computer.js similarity index 100% rename from week-2/Homework/mandatory/3-playing-computer.js rename to week-2/.archive/mandatory/3-playing-computer.js diff --git a/week-2/Homework/mandatory/4-sorting-algorithm.js b/week-2/.archive/mandatory/4-sorting-algorithm.js similarity index 100% rename from week-2/Homework/mandatory/4-sorting-algorithm.js rename to week-2/.archive/mandatory/4-sorting-algorithm.js diff --git a/week-2/.archive/A-expressions/README.md b/week-2/Homework/A-expressions/README.md similarity index 100% rename from week-2/.archive/A-expressions/README.md rename to week-2/Homework/A-expressions/README.md diff --git a/week-2/.archive/B-boolean-literals/README.md b/week-2/Homework/B-boolean-literals/README.md similarity index 100% rename from week-2/.archive/B-boolean-literals/README.md rename to week-2/Homework/B-boolean-literals/README.md diff --git a/week-2/.archive/B-boolean-literals/exercise.js b/week-2/Homework/B-boolean-literals/exercise.js similarity index 100% rename from week-2/.archive/B-boolean-literals/exercise.js rename to week-2/Homework/B-boolean-literals/exercise.js diff --git a/week-2/.archive/C-comparison-operators/README.md b/week-2/Homework/C-comparison-operators/README.md similarity index 100% rename from week-2/.archive/C-comparison-operators/README.md rename to week-2/Homework/C-comparison-operators/README.md diff --git a/week-2/.archive/C-comparison-operators/exercise.js b/week-2/Homework/C-comparison-operators/exercise.js similarity index 100% rename from week-2/.archive/C-comparison-operators/exercise.js rename to week-2/Homework/C-comparison-operators/exercise.js diff --git a/week-2/.archive/D-predicates/README.md b/week-2/Homework/D-predicates/README.md similarity index 100% rename from week-2/.archive/D-predicates/README.md rename to week-2/Homework/D-predicates/README.md diff --git a/week-2/.archive/D-predicates/exercise.js b/week-2/Homework/D-predicates/exercise.js similarity index 100% rename from week-2/.archive/D-predicates/exercise.js rename to week-2/Homework/D-predicates/exercise.js diff --git a/week-2/.archive/E-conditionals/README.md b/week-2/Homework/E-conditionals/README.md similarity index 100% rename from week-2/.archive/E-conditionals/README.md rename to week-2/Homework/E-conditionals/README.md diff --git a/week-2/.archive/E-conditionals/exercise.js b/week-2/Homework/E-conditionals/exercise.js similarity index 100% rename from week-2/.archive/E-conditionals/exercise.js rename to week-2/Homework/E-conditionals/exercise.js diff --git a/week-2/.archive/F-logical-operators/README.md b/week-2/Homework/F-logical-operators/README.md similarity index 100% rename from week-2/.archive/F-logical-operators/README.md rename to week-2/Homework/F-logical-operators/README.md diff --git a/week-2/.archive/F-logical-operators/exercise.js b/week-2/Homework/F-logical-operators/exercise.js similarity index 100% rename from week-2/.archive/F-logical-operators/exercise.js rename to week-2/Homework/F-logical-operators/exercise.js diff --git a/week-2/.archive/F-logical-operators/exercise2.js b/week-2/Homework/F-logical-operators/exercise2.js similarity index 100% rename from week-2/.archive/F-logical-operators/exercise2.js rename to week-2/Homework/F-logical-operators/exercise2.js diff --git a/week-2/.archive/G-conditionals-2/README.md b/week-2/Homework/G-conditionals-2/README.md similarity index 100% rename from week-2/.archive/G-conditionals-2/README.md rename to week-2/Homework/G-conditionals-2/README.md diff --git a/week-2/.archive/G-conditionals-2/exercise-1.js b/week-2/Homework/G-conditionals-2/exercise-1.js similarity index 100% rename from week-2/.archive/G-conditionals-2/exercise-1.js rename to week-2/Homework/G-conditionals-2/exercise-1.js diff --git a/week-2/.archive/G-conditionals-2/exercise-2.js b/week-2/Homework/G-conditionals-2/exercise-2.js similarity index 100% rename from week-2/.archive/G-conditionals-2/exercise-2.js rename to week-2/Homework/G-conditionals-2/exercise-2.js diff --git a/week-2/.archive/G-conditionals-2/exercise-3.js b/week-2/Homework/G-conditionals-2/exercise-3.js similarity index 100% rename from week-2/.archive/G-conditionals-2/exercise-3.js rename to week-2/Homework/G-conditionals-2/exercise-3.js diff --git a/week-2/.archive/G-conditionals-2/exercise-4.js b/week-2/Homework/G-conditionals-2/exercise-4.js similarity index 100% rename from week-2/.archive/G-conditionals-2/exercise-4.js rename to week-2/Homework/G-conditionals-2/exercise-4.js diff --git a/week-2/Homework/H-loops/exercise-1.js b/week-2/Homework/H-loops/exercise-1.js new file mode 100644 index 000000000..613ec058c --- /dev/null +++ b/week-2/Homework/H-loops/exercise-1.js @@ -0,0 +1,65 @@ +/* + While Loops + --------------------------------- + + Using while loops complete the exercises to output the + correct results. +*/ + +//The while loop outputs "Hello" 10 times. Change the code so it only outputs "Hello" 5 times + +let i = 0; +while(i < 10) { + console.log("Hello"); + i++ +} + +//This while loop doesn't do anything! Change the code so it outputs the sentence "Coding is easy" 3 times + +let j = 0; +while(j < 5) { + + j++ +} + +// This while loop uses the variable loopLimit in its condition. +// Change the code below so it outputs "Goodbye" 5 times + +let loopLimit = 2; +k = 0; +while(k < loopLimit) { //don't change this line + console.log("Goodbye"); + k++ +} + + +/* + Write a while loop that prints "eating 1 slice of pizza" 6 times to the console. + + Use the variables slices and hungry to create a condition. + If hungry is greater than slices, then we will eat a slice of pizza. + If hungry is the same as slices then the loop terminates. + + Don't forget to increase (slices ++) inside the while loop. + + - HINT: check the cake example in the week-2 presentation + + */ + + let slices = 0; + const hungry = 6; + + // add your code here, start with: while(...) {...} + + + + /* + EXPECTED RESULT + --------------- + eating 1 slice of pizza + eating 1 slice of pizza + eating 1 slice of pizza + eating 1 slice of pizza + eating 1 slice of pizza + eating 1 slice of pizza + */ diff --git a/week-2/Homework/H-loops/exercise-2.js b/week-2/Homework/H-loops/exercise-2.js new file mode 100644 index 000000000..9649f8704 --- /dev/null +++ b/week-2/Homework/H-loops/exercise-2.js @@ -0,0 +1,59 @@ +/* +For-Loops +--------------------------------- +Exercise 2-a: +--------------------------------- + + + I have a for loop, that counts from 1 to 10. + Can you change so that it counts down from 10 to 1? + */ + + for(let number = 1; number <= 10; number++) { + console.log(number); + } + + + /* + EXPECTED RESULT + --------------- + 10 + 9 + 8 + 7 + 6 + 5 + 4 + 3 + 2 + 1 + */ + + + + /* +Exercise 2-b: +--------------------------------- + + Great work! :) Now create a for loop the prints "drinking a glass of water" 4 times to the console. + + Use the glass variable inside the for loop. + If the value of glass is smaller than 4, then print "drinking a glass of water" + + - HINT: check the for loop cake example in the week-2 presentation + + */ + + let glass = 0; + + // add your code here, starting with: for(...) {...} + + + /* + EXPECTED RESULT + --------------- + drinking a glass of water + drinking a glass of water + drinking a glass of water + drinking a glass of water + */ \ No newline at end of file diff --git a/week-2/.archive/H-array-literals/README.md b/week-2/Homework/I-array-literals/README.md similarity index 100% rename from week-2/.archive/H-array-literals/README.md rename to week-2/Homework/I-array-literals/README.md diff --git a/week-2/.archive/H-array-literals/exercise.js b/week-2/Homework/I-array-literals/exercise.js similarity index 100% rename from week-2/.archive/H-array-literals/exercise.js rename to week-2/Homework/I-array-literals/exercise.js diff --git a/week-2/.archive/J-array-get-set/README.md b/week-2/Homework/J-array-get-set/README.md similarity index 100% rename from week-2/.archive/J-array-get-set/README.md rename to week-2/Homework/J-array-get-set/README.md diff --git a/week-2/.archive/J-array-get-set/exercise.js b/week-2/Homework/J-array-get-set/exercise.js similarity index 100% rename from week-2/.archive/J-array-get-set/exercise.js rename to week-2/Homework/J-array-get-set/exercise.js diff --git a/week-2/.archive/J-array-get-set/exercises2.js b/week-2/Homework/J-array-get-set/exercises2.js similarity index 100% rename from week-2/.archive/J-array-get-set/exercises2.js rename to week-2/Homework/J-array-get-set/exercises2.js diff --git a/week-2/.archive/I-array-properties/README.md b/week-2/Homework/K-array-properties/README.md similarity index 100% rename from week-2/.archive/I-array-properties/README.md rename to week-2/Homework/K-array-properties/README.md diff --git a/week-2/.archive/I-array-properties/exercise.js b/week-2/Homework/K-array-properties/exercise.js similarity index 100% rename from week-2/.archive/I-array-properties/exercise.js rename to week-2/Homework/K-array-properties/exercise.js diff --git a/week-2/Homework/L-extra/level-1/1-boolean.js b/week-2/Homework/L-extra/level-1/1-boolean.js new file mode 100644 index 000000000..8c4290152 --- /dev/null +++ b/week-2/Homework/L-extra/level-1/1-boolean.js @@ -0,0 +1,16 @@ +// The code is valid but the program does not produce the expected result +// Fix it. + +var isHappy = false; + +if (isHappy) { + console.log("I am happy"); +} else { + console.log("I am not happy"); +} + +/* + EXPECTED RESULT + --------------- + I am happy +*/ diff --git a/week-2/Homework/L-extra/level-1/2-validation.js b/week-2/Homework/L-extra/level-1/2-validation.js new file mode 100644 index 000000000..4c34981e0 --- /dev/null +++ b/week-2/Homework/L-extra/level-1/2-validation.js @@ -0,0 +1,17 @@ +// Update the variable `isBigEnough` so that the program produces the expected result +// TIP: You should write an expression that returns a boolean value + +var num = 10; +var isBigEnough; // ONLY EDIT THIS LINE + +if (isBigEnough) { + console.log("num is bigger than or equal to 10"); +} else { + console.log("num is not big enough"); +} + +/* + EXPECTED RESULT + --------------- + num is bigger than or equal to 10 +*/ diff --git a/week-2/Homework/L-extra/level-1/3-sort.js b/week-2/Homework/L-extra/level-1/3-sort.js new file mode 100644 index 000000000..136bc8cb9 --- /dev/null +++ b/week-2/Homework/L-extra/level-1/3-sort.js @@ -0,0 +1,13 @@ +// Update the variable `sortedLetters` so that it contains the values of `letters` in ascending order +// TIP: use an array method + +var letters = ["a", "n", "c", "e", "z", "f"]; +var sortedLetters; // ONLY EDIT THIS LINE + +console.log(sortedLetters); + +/* + EXPECTED RESULT + --------------- + [ 'a', 'c', 'e', 'f', 'n', 'z' ] +*/ diff --git a/week-2/Homework/L-extra/level-1/4-slice.js b/week-2/Homework/L-extra/level-1/4-slice.js new file mode 100644 index 000000000..6183df636 --- /dev/null +++ b/week-2/Homework/L-extra/level-1/4-slice.js @@ -0,0 +1,16 @@ +// Write a function `first5` that: +// - returns the first 5 items from a provided array + +/* + DO NOT EDIT BELOW THIS LINE + --------------------------- */ +var numbers = [1, 2, 3, 4, 5, 6, 7, 8]; +var first5Numbers = first5(numbers); + +console.log(first5Numbers); + +/* + EXPECTED RESULT + --------------- + [1, 2, 3, 4, 5] +*/ diff --git a/week-2/Homework/L-extra/level-1/5-indexOf.js b/week-2/Homework/L-extra/level-1/5-indexOf.js new file mode 100644 index 000000000..bb99819a5 --- /dev/null +++ b/week-2/Homework/L-extra/level-1/5-indexOf.js @@ -0,0 +1,14 @@ +// Find the index of an item in an array +// TIP: use the .indexOf() method (search the web for documentation if you're not sure) + +var itemToFind = 7; +var arr = [3, 5, 61, 7, 123]; +var index; // ONLY EDIT THIS LINE + +console.log(index); + +/* + EXPECTED RESULT + --------------- + 3 +*/ diff --git a/week-2/Homework/L-extra/level-1/6-map.js b/week-2/Homework/L-extra/level-1/6-map.js new file mode 100644 index 000000000..520311c53 --- /dev/null +++ b/week-2/Homework/L-extra/level-1/6-map.js @@ -0,0 +1,22 @@ +// An array of mentor names has been provided to you, as well as a function to tidy up strings. +// Declare a new array (`mentorsTidy`) containing: +// - every item from `mentors` run through the `tidyUpString` function +// TIP: Use the .map() method + +function tidyUpString(str) { + return str + .trim() + .toLowerCase() + .replace("/", ""); +} + +var mentors = ["/Daniel ", "irina ", " Gordon", "ashleigh "]; +var mentorsTidy; // ONLY EDIT THIS LINE + +console.log(mentorsTidy); + +/* + EXPECTED RESULT + --------------- + ["daniel", "irina", "gordon", "ashleigh"] +*/ diff --git a/week-2/Homework/L-extra/level-2/1-boolean.js b/week-2/Homework/L-extra/level-2/1-boolean.js new file mode 100644 index 000000000..b1aa23a01 --- /dev/null +++ b/week-2/Homework/L-extra/level-2/1-boolean.js @@ -0,0 +1,17 @@ +// The code is valid but the program does not produce the expected result +// Why doesn't it work? +// Fix it. + +var isHappy = "false"; + +if (isHappy) { + console.log("I am happy"); +} else { + console.log("I am not happy"); +} + +/* + EXPECTED RESULT + --------------- + I am not happy +*/ diff --git a/week-2/Homework/L-extra/level-2/2-validation.js b/week-2/Homework/L-extra/level-2/2-validation.js new file mode 100644 index 000000000..2e76d6674 --- /dev/null +++ b/week-2/Homework/L-extra/level-2/2-validation.js @@ -0,0 +1,27 @@ +// Complete the function to check if the variable `num` satisfies the following requirements: +// - is a number +// - is a positive number +// - is less than or equal to 100 +// Tip: write other small functions for each requirement + +function validate(num) {} + +/* + DO NOT EDIT BELOW THIS LINE + --------------------------- */ + +console.log(validate(10)); +console.log(validate(10.5)); +console.log(validate(101)); +console.log(validate(-12)); +console.log(validate("16")); + +/* + EXPECTED RESULT + --------------- + true + true + false + false + false +*/ diff --git a/week-2/Homework/L-extra/level-2/3-sort.js b/week-2/Homework/L-extra/level-2/3-sort.js new file mode 100644 index 000000000..d288f6ab4 --- /dev/null +++ b/week-2/Homework/L-extra/level-2/3-sort.js @@ -0,0 +1,14 @@ +// Update the variable `sortedLetters`. +// It should contain the values of `letters` and `letters2` in ascending order + +var letters = ["a", "n", "c", "e", "z", "f"]; +var letters2 = ["w", "b", "v", "g", "l", "o"]; +var sortedLetters; // ONLY EDIT THIS LINE + +console.log(sortedLetters); + +/* + EXPECTED RESULT + --------------- + [ 'a', 'b', 'c', 'e', 'f', 'g', 'l','n', 'o', 'v', 'w', 'z' ] +*/ diff --git a/week-2/Homework/L-extra/level-2/4-slice.js b/week-2/Homework/L-extra/level-2/4-slice.js new file mode 100644 index 000000000..c02726e61 --- /dev/null +++ b/week-2/Homework/L-extra/level-2/4-slice.js @@ -0,0 +1,28 @@ +// Write a function that removes an element from an array +// The function must: +// - NOT change the original array +// - return a new array with the item removed +// - remove the item at the specified index + +function remove(arr, index) { + return; // complete this statement +} + +/* + DO NOT EDIT BELOW THIS LINE + --------------------------- */ +var numbers = [1, 2, 3]; +var names = ["Irina", "Ashleigh", "Mozafar"]; + +var newNumbers = remove(numbers, 2); +var newNames = remove(names, 1); + +console.log(newNumbers); +console.log(newNames); + +/* + EXPECTED RESULT + --------------- + [1, 2] + [Irina, Mozafar] +*/ diff --git a/week-2/Homework/L-extra/level-2/5-indexOf.js b/week-2/Homework/L-extra/level-2/5-indexOf.js new file mode 100644 index 000000000..204440b11 --- /dev/null +++ b/week-2/Homework/L-extra/level-2/5-indexOf.js @@ -0,0 +1,28 @@ +// Write a function that removes an element from an array +// The function must: +// - NOT change the original array +// - return a new array with the first item matching `valueToRemove` removed +// TIP: Use the .indexOf() method + +function remove(arr, valueToRemove) { + return; // complete this statement +} + +/* + DO NOT EDIT BELOW THIS LINE + --------------------------- */ +var numbers = [1, 2, 3]; +var names = ["Irina", "Ashleigh", "Mozafar"]; + +var newNumbers = remove(numbers, 2); +var newNames = remove(names, "Ashleigh"); + +console.log(newNumbers); +console.log(newNames); + +/* + EXPECTED RESULT + --------------- + [1, 3] + [Irina, Mozafar] +*/ diff --git a/week-2/Homework/L-extra/level-2/6-map.js b/week-2/Homework/L-extra/level-2/6-map.js new file mode 100644 index 000000000..0e2e10ab1 --- /dev/null +++ b/week-2/Homework/L-extra/level-2/6-map.js @@ -0,0 +1,14 @@ +// You have been given an array of percetages +// 1. Write a function that formats the numbers into a string with the percentage symbol appended e.g. "10%" +// 2. Declare a new array, `percentagesFormatted`, containing +// - each item in `percentages` formatted by your function + +var percentages = [1, 23, 92, 18]; + +console.log(percentagesFormatted); + +/* + EXPECTED RESULT + --------------- + [1%, 23%, 92%, 18%] +*/ diff --git a/week-2/Homework/L-extra/level-3/1-boolean.js b/week-2/Homework/L-extra/level-3/1-boolean.js new file mode 100644 index 000000000..4f2c44e39 --- /dev/null +++ b/week-2/Homework/L-extra/level-3/1-boolean.js @@ -0,0 +1,18 @@ +// The code is valid but is misleading and could be improved +// Refactor the code to make it better +// What was wrong with the original code? +// Leave comments above your changes to explain + +var isHappy = "false"; + +if (isHappy == true) { + console.log("I am happy"); +} else { + console.log("I am not happy"); +} + +/* + EXPECTED RESULT + --------------- + I am not happy +*/ diff --git a/week-2/Homework/L-extra/level-3/2-validation.js b/week-2/Homework/L-extra/level-3/2-validation.js new file mode 100644 index 000000000..d12a8cf0d --- /dev/null +++ b/week-2/Homework/L-extra/level-3/2-validation.js @@ -0,0 +1,25 @@ +// Complete the function to check if the variable `num` satisfies the following requirements: +// - is a number +// - is an integer (not a float) +// - is not equal any of the numbers in the array `excludedNums` +// Tip: write other small functions for each requirement + +var excludedNums = [6, 14, 91, 111]; + +function validate(num) {} + +console.log(validate(6)); +console.log(validate(10.5)); +console.log(validate(101)); +console.log(validate(-91)); +console.log(validate("16")); + +/* + EXPECTED RESULT + --------------- + false + false + true + true + false +*/ diff --git a/week-2/Homework/L-extra/level-3/3-sort.js b/week-2/Homework/L-extra/level-3/3-sort.js new file mode 100644 index 000000000..8d3dddae7 --- /dev/null +++ b/week-2/Homework/L-extra/level-3/3-sort.js @@ -0,0 +1,17 @@ +// 1. Update the variable `sortedNums`. +// It should contain the values of `nums` and `nums2` in ascending order +// Tip: you might need to read the documentation for .sort (search "mdn array sort") + +var nums = [10, 1, 5, 29, 100]; +var nums2 = [11, 6, 3, 29, 12]; +var sortedNums; // complete this statement + +console.log(sortedNums); + +// 2. Using code, show that the variables nums and nums2 were not changed + +/* + EXPECTED RESULT + --------------- + [ 1, 3, 5, 6, 10, 11, 12, 29, 29, 100 ] +*/ diff --git a/week-2/Homework/L-extra/level-3/4-slice.js b/week-2/Homework/L-extra/level-3/4-slice.js new file mode 100644 index 000000000..79911f127 --- /dev/null +++ b/week-2/Homework/L-extra/level-3/4-slice.js @@ -0,0 +1,32 @@ +// Write a function that replaces an element in an array +// The function must: +// - NOT change the original array +// - return a new array with the replacement value inserted +// - insert the replacement value at the provided index + +function replace(arr, index, value) { + return; // complete this statement +} + +/* + DO NOT EDIT BELOW THIS LINE + --------------------------- */ +var numbers = [1, 3, 3]; +var names = ["Irina", "Ashleigh", "Mozafar"]; + +var newNumbers = replace(numbers, 1, 2); +var newNames = replace(names, 2, "Rares"); + +console.log(numbers); +console.log(newNumbers); +console.log(names); +console.log(newNames); + +/* + EXPECTED RESULT + --------------- + [1, 3, 3] + [1, 2, 3] + [Irina, Ashleigh, Mozafar] + [Irina, Ashleigh, Rares] +*/ diff --git a/week-2/Homework/L-extra/level-3/5-indexOf.js b/week-2/Homework/L-extra/level-3/5-indexOf.js new file mode 100644 index 000000000..f24e500e4 --- /dev/null +++ b/week-2/Homework/L-extra/level-3/5-indexOf.js @@ -0,0 +1,33 @@ +// Write a function that replaces an element in an array +// The function must: +// - get the index of the first item matching `valueToReplace` +// - insert `newValue` at that index +// - NOT change the original array +// - return a new array with the replacement value inserted + +function replace(arr, valueToReplace, newValue) { + return; // complete this statement +} + +/* + DO NOT EDIT BELOW THIS LINE + --------------------------- */ +var numbers = [1, 3, 3]; +var names = ["Irina", "Ashleigh", "Mozafar"]; + +var newNumbers = replace(arr, 3, 2); +var newNames = replace(arr, "Ashleigh", "Rares"); + +console.log(numbers); +console.log(newNumbers); +console.log(names); +console.log(newNames); + +/* + EXPECTED RESULT + --------------- + [1, 3, 3] + [1, 2, 3] + [Irina, Ashleigh, Mozafar] + [Irina, Rares, Mozafar] +*/ diff --git a/week-2/Homework/L-extra/level-3/6-map.js b/week-2/Homework/L-extra/level-3/6-map.js new file mode 100644 index 000000000..42db906a2 --- /dev/null +++ b/week-2/Homework/L-extra/level-3/6-map.js @@ -0,0 +1,26 @@ +// 1. Write a function (`capitalise`) that capitalises the first letter of a provided string +// 2. Declare a new array (`mentorsTidy`) containing: +// - every item from `mentors` run through the `tidyUpString` function +// - every resulting item run through the `capitalise` function + +function tidyUpString(str) { + return str + .trim() + .toLowerCase() + .replace("/", ""); +} + +function capitalise(str) { + // complete this function +} + +var mentors = ["/Daniel ", "irina ", " Gordon", "ashleigh "]; +var mentorsTidyAndCapitalised; + +console.log(mentorsTidyAndCapitalised); + +/* + EXPECTED RESULT + --------------- + ["Daniel", "Irina", "Gordon", "Ashleigh"] +*/ diff --git a/week-3/Homework/extra/1-card-vailidator.md b/week-3/.archive/extra/1-card-vailidator.md similarity index 100% rename from week-3/Homework/extra/1-card-vailidator.md rename to week-3/.archive/extra/1-card-vailidator.md diff --git a/week-3/Homework/mandatory/0-freecodecamp.md b/week-3/.archive/mandatory/0-freecodecamp.md similarity index 100% rename from week-3/Homework/mandatory/0-freecodecamp.md rename to week-3/.archive/mandatory/0-freecodecamp.md diff --git a/week-3/Homework/mandatory/1-oxygen-levels.js b/week-3/.archive/mandatory/1-oxygen-levels.js similarity index 100% rename from week-3/Homework/mandatory/1-oxygen-levels.js rename to week-3/.archive/mandatory/1-oxygen-levels.js diff --git a/week-3/Homework/mandatory/2-bush-berries.js b/week-3/.archive/mandatory/2-bush-berries.js similarity index 100% rename from week-3/Homework/mandatory/2-bush-berries.js rename to week-3/.archive/mandatory/2-bush-berries.js diff --git a/week-3/Homework/mandatory/3-space-colonies.js b/week-3/.archive/mandatory/3-space-colonies.js similarity index 100% rename from week-3/Homework/mandatory/3-space-colonies.js rename to week-3/.archive/mandatory/3-space-colonies.js diff --git a/week-3/Homework/mandatory/4-eligible-students.js b/week-3/.archive/mandatory/4-eligible-students.js similarity index 100% rename from week-3/Homework/mandatory/4-eligible-students.js rename to week-3/.archive/mandatory/4-eligible-students.js diff --git a/week-3/Homework/mandatory/5-journey-planner.js b/week-3/.archive/mandatory/5-journey-planner.js similarity index 100% rename from week-3/Homework/mandatory/5-journey-planner.js rename to week-3/.archive/mandatory/5-journey-planner.js diff --git a/week-3/Homework/mandatory/6-lane-names.js b/week-3/.archive/mandatory/6-lane-names.js similarity index 100% rename from week-3/Homework/mandatory/6-lane-names.js rename to week-3/.archive/mandatory/6-lane-names.js diff --git a/week-3/Homework/mandatory/7-password-validator.js b/week-3/.archive/mandatory/7-password-validator.js similarity index 100% rename from week-3/Homework/mandatory/7-password-validator.js rename to week-3/.archive/mandatory/7-password-validator.js diff --git a/week-3/Homework/mandatory/8-codewars.md b/week-3/.archive/mandatory/8-codewars.md similarity index 98% rename from week-3/Homework/mandatory/8-codewars.md rename to week-3/.archive/mandatory/8-codewars.md index b9cab92f1..8bd2b85c5 100644 --- a/week-3/Homework/mandatory/8-codewars.md +++ b/week-3/.archive/mandatory/8-codewars.md @@ -1,33 +1,33 @@ -# Codewars Exercises - -Today, you'll be using a platform called [CodeWars](https://codewars.com) to help you recap the materials you learnt in JS1. CodeWars is an excellent platform for going through interesting JavaScript exercises, and allows you to communicate with the wider community to learn about the best way of writing JavaScript code. - -1. Make sure you finish all the pending exercies in week-1, week-2 and week-3 of the [js-exercises repo](https://github.com/CodeYourFuture/js-exercises). - -2. Signup to [CodeWars](https://codewars.com) and work on these challenges: - -*Functions, types, conditionals etc...* - -- [even or odd](https://www.codewars.com/kata/even-or-odd/train/javascript) -- [code under pressure](https://www.codewars.com/kata/you-cant-code-under-pressure-number-1/train/javascript) -- [secret message](https://www.codewars.com/kata/jennys-secret-message/train/javascript) -- [convert boolean](https://www.codewars.com/kata/convert-boolean-values-to-strings-yes-or-no/train/javascript) -- [opposite number](https://www.codewars.com/kata/opposite-number/train/javascript) -- [return negative](https://www.codewars.com/kata/return-negative/train/javascript) -- [hydrated](https://www.codewars.com/kata/keep-hydrated-1/train/javascript) -- [bonus](https://www.codewars.com/kata/do-i-get-a-bonus/train/javascript) -- [remove string spaces](https://www.codewars.com/kata/remove-string-spaces/train/javascript) -- [remove first and last character](https://www.codewars.com/kata/remove-first-and-last-character/train/javascript) -- [string repeat](https://www.codewars.com/kata/string-repeat/train/javascript) -- [mathematical operations](https://www.codewars.com/kata/basic-mathematical-operations/train/javascript) - -*Arrays* - -- [invert values](https://www.codewars.com/kata/invert-values/train/javascript) -- [needle in haystack](https://www.codewars.com/kata/a-needle-in-the-haystack/train/javascript) -- [counting sheep](https://www.codewars.com/kata/counting-sheep-dot-dot-dot/train/javascript) -- [sum of positive](https://www.codewars.com/kata/sum-of-positive/train/javascript) -- [people in bus](https://www.codewars.com/kata/number-of-people-in-the-bus/train/javascript) -- [sum without highest and lowest](https://www.codewars.com/kata/sum-without-highest-and-lowest-number/train/javascript) -- [reveersed array of digits](https://www.codewars.com/kata/convert-number-to-reversed-array-of-digits/train/javascript) +# Codewars Exercises + +Today, you'll be using a platform called [CodeWars](https://codewars.com) to help you recap the materials you learnt in JS1. CodeWars is an excellent platform for going through interesting JavaScript exercises, and allows you to communicate with the wider community to learn about the best way of writing JavaScript code. + +1. Make sure you finish all the pending exercies in week-1, week-2 and week-3 of the [js-exercises repo](https://github.com/CodeYourFuture/js-exercises). + +2. Signup to [CodeWars](https://codewars.com) and work on these challenges: + +*Functions, types, conditionals etc...* + +- [even or odd](https://www.codewars.com/kata/even-or-odd/train/javascript) +- [code under pressure](https://www.codewars.com/kata/you-cant-code-under-pressure-number-1/train/javascript) +- [secret message](https://www.codewars.com/kata/jennys-secret-message/train/javascript) +- [convert boolean](https://www.codewars.com/kata/convert-boolean-values-to-strings-yes-or-no/train/javascript) +- [opposite number](https://www.codewars.com/kata/opposite-number/train/javascript) +- [return negative](https://www.codewars.com/kata/return-negative/train/javascript) +- [hydrated](https://www.codewars.com/kata/keep-hydrated-1/train/javascript) +- [bonus](https://www.codewars.com/kata/do-i-get-a-bonus/train/javascript) +- [remove string spaces](https://www.codewars.com/kata/remove-string-spaces/train/javascript) +- [remove first and last character](https://www.codewars.com/kata/remove-first-and-last-character/train/javascript) +- [string repeat](https://www.codewars.com/kata/string-repeat/train/javascript) +- [mathematical operations](https://www.codewars.com/kata/basic-mathematical-operations/train/javascript) + +*Arrays* + +- [invert values](https://www.codewars.com/kata/invert-values/train/javascript) +- [needle in haystack](https://www.codewars.com/kata/a-needle-in-the-haystack/train/javascript) +- [counting sheep](https://www.codewars.com/kata/counting-sheep-dot-dot-dot/train/javascript) +- [sum of positive](https://www.codewars.com/kata/sum-of-positive/train/javascript) +- [people in bus](https://www.codewars.com/kata/number-of-people-in-the-bus/train/javascript) +- [sum without highest and lowest](https://www.codewars.com/kata/sum-without-highest-and-lowest-number/train/javascript) +- [reveersed array of digits](https://www.codewars.com/kata/convert-number-to-reversed-array-of-digits/train/javascript) - [slash sum of negatives](https://www.codewars.com/kata/count-of-positives-slash-sum-of-negatives/train/javascript) \ No newline at end of file diff --git a/week-3/.archive/A-array-find/README.md b/week-3/Homework/A-array-find/README.md similarity index 100% rename from week-3/.archive/A-array-find/README.md rename to week-3/Homework/A-array-find/README.md diff --git a/week-3/.archive/A-array-find/exercise.js b/week-3/Homework/A-array-find/exercise.js similarity index 100% rename from week-3/.archive/A-array-find/exercise.js rename to week-3/Homework/A-array-find/exercise.js diff --git a/week-3/.archive/B-array-some/README.md b/week-3/Homework/B-array-some/README.md similarity index 100% rename from week-3/.archive/B-array-some/README.md rename to week-3/Homework/B-array-some/README.md diff --git a/week-3/.archive/B-array-some/exercise.js b/week-3/Homework/B-array-some/exercise.js similarity index 100% rename from week-3/.archive/B-array-some/exercise.js rename to week-3/Homework/B-array-some/exercise.js diff --git a/week-3/.archive/C-array-every/README.md b/week-3/Homework/C-array-every/README.md similarity index 100% rename from week-3/.archive/C-array-every/README.md rename to week-3/Homework/C-array-every/README.md diff --git a/week-3/.archive/C-array-every/exercise.js b/week-3/Homework/C-array-every/exercise.js similarity index 100% rename from week-3/.archive/C-array-every/exercise.js rename to week-3/Homework/C-array-every/exercise.js diff --git a/week-3/.archive/D-array-filter/README.md b/week-3/Homework/D-array-filter/README.md similarity index 100% rename from week-3/.archive/D-array-filter/README.md rename to week-3/Homework/D-array-filter/README.md diff --git a/week-3/.archive/D-array-filter/exercise.js b/week-3/Homework/D-array-filter/exercise.js similarity index 100% rename from week-3/.archive/D-array-filter/exercise.js rename to week-3/Homework/D-array-filter/exercise.js diff --git a/week-3/.archive/E-array-map/README.md b/week-3/Homework/E-array-map/README.md similarity index 100% rename from week-3/.archive/E-array-map/README.md rename to week-3/Homework/E-array-map/README.md diff --git a/week-3/.archive/E-array-map/exercise.js b/week-3/Homework/E-array-map/exercise.js similarity index 100% rename from week-3/.archive/E-array-map/exercise.js rename to week-3/Homework/E-array-map/exercise.js diff --git a/week-3/.archive/F-array-forEach/README.md b/week-3/Homework/F-array-forEach/README.md similarity index 100% rename from week-3/.archive/F-array-forEach/README.md rename to week-3/Homework/F-array-forEach/README.md diff --git a/week-3/.archive/F-array-forEach/exercise.js b/week-3/Homework/F-array-forEach/exercise.js similarity index 100% rename from week-3/.archive/F-array-forEach/exercise.js rename to week-3/Homework/F-array-forEach/exercise.js diff --git a/week-3/Homework/G-extra/1-map.js b/week-3/Homework/G-extra/1-map.js new file mode 100644 index 000000000..453b67a91 --- /dev/null +++ b/week-3/Homework/G-extra/1-map.js @@ -0,0 +1,21 @@ +/* + I am new to London and would like to know what transport I can take to different famous locations. + An array with London locations have been provided. + Using .filter(), .map(), and any other array methods required, create: + - a new array of stations with travel by river boat + Note: only the names should be printed, not the means of transport. +*/ + +var stationTransportOptionsPairs = [ + ["Angel", ["tube", "bus"]], + ["London Bridge", ["tube", "bus", "river boat"]], + ["Tower bridge", ["tube", "bus"]], + ["Greenwich", ["tube", "bus", "river boat"]] +]; + +var stationsWithRiverBoat; // <-- Complete this statement + +console.log(stationsWithRiverBoat); + +// Expected output: +// ["London Bridge", "Greenwich"] diff --git a/week-3/Homework/G-extra/2-map.js b/week-3/Homework/G-extra/2-map.js new file mode 100644 index 000000000..a9ea412d2 --- /dev/null +++ b/week-3/Homework/G-extra/2-map.js @@ -0,0 +1,24 @@ +/* + Only students who have attended enough classes are eligible to sit an exam. + You have an array named `attendanceCounts` which contains all the students' names and their attendance counts. + Using .filter() and .map(), create a new array named "eligibleStudentNames" containing: + - only the NAMES of the students who have attended AT LEAST 8 classes. +*/ + +var attendanceCounts = [ + ["Ahmed", 8], + ["Clement", 10], + ["Elamin", 6], + ["Adam", 7], + ["Tayoa", 11], + ["Nina", 10] +]; + +var eligibleStudentNames; // TODO: Complete this line. + +console.log(eligibleStudentNames); + +/* expected output +[ 'Ahmed', 'Clement', 'Tayoa', 'Nina' ] +Note: student attendance counts should NOT be included in your console output. +*/ diff --git a/week-3/Homework/G-extra/3-filter.js b/week-3/Homework/G-extra/3-filter.js new file mode 100644 index 000000000..263b14e0f --- /dev/null +++ b/week-3/Homework/G-extra/3-filter.js @@ -0,0 +1,560 @@ +/* + You are given a list of some London street names. + We would like to know all of the names which contain 'Lane' their name. +*/ + +var streetNames = [ + "Abchurch Lane", + "Adam's Court", + "Addle Hill", + "Addle Street", + "Alban Highwalk", + "Albion Place", + "Albion Way", + "Aldermanbury", + "Alderman's Walk", + "Aldersgate Court", + "Aldgate", + "Allhallows Lane", + "Amen Corner", + "America Square", + "Andrewes Highwalk", + "Angel Court", + "Angel Lane", + "Angel Street", + "Apothecary Street", + "Appold Stree", + "The Arcade", + "Arthur Street", + "Artillery Lane", + "Artizan Street", + "Ashentree Court", + "Athene Place", + "Austin Friars", + "Ave Maria Lane", + "The Avenue", + "Back Alley", + "Back Passage", + "Bakers Hall Court", + "Ball Court", + "Baltic Street West", + "Barbon Alley", + "Barley Mow Passage", + "Barnard's Inn", + "Bartholomew Close", + "Bartholomew Lane", + "Bartlett Court", + "Basinghall Avenue", + "Bassishaw Highwalk", + "Bastion Highwalk", + "Bear Alley", + "Beech Gardens", + "Beehive Passage", + "Bengal Court", + "Bell Court", + "Bell Inn Yard", + "Bell Wharf Lane", + "Ben Jonson Place", + "Bennet's Hill", + "Bevis Marks", + "Billiter Court", + "Birchin Lane", + "Bishop's Court", + "Bishopsgate", + "Blackfriars Bridge", + "Blackfriars Court", + "Blackfriars Lane", + "Blackfriars Passage", + "Blomfield Street", + "Bloomberg Arcade", + "Bolt Court", + "Bond Court", + "Booth Lane", + "Botolph Alley", + "Bouverie Street", + "Bow Churchyard", + "Brabant Court", + "Brackley Street", + "Braidwood Passage", + "Brandon Mews", + "Bread Street", + "Bream's Buildings", + "Breton Highwalk", + "Brewer's Hall Gardens", + "Brick Court", + "Bride Court", + "Bridewell Place", + "Bridgewater Highwalk", + "Britannic Highwalk", + "Broadgate", + "Broad Lane", + "Broken Wharf", + "Brown's Buildings", + "Brushfield Street", + "Bucklersbury", + "Budge Row", + "Bull's Head Passage", + "Bunyan Court", + "Burgon Street", + "Bury Court", + "Bush Lane", + "Byward Street", + "Camomile Street", + "Canon Alley", + "Cannon Street", + "Capel Court", + "Carlisle Avenue", + "Carmelite Street", + "Carter Court", + "Carthusian Street", + "Castle Baynard Street", + "Castle Court", + "Catherine Wheel Alley", + "Cavendish Court", + "Chancery Lane", + "Change Alley", + "Charterhouse Square", + "Cheapside", + "Cheshire Court", + "Chiswell Street", + "Church Cloisters", + "Church Court", + "Church Entry", + "Circus Place", + "Clements Lane", + "Clerk's Place", + "Clifford's Inn Passage", + "Cloak Lane", + "Cloth Court", + "Clothier Street", + "Cobb's Court", + "Cock Hill", + "Cock Lane", + "Coleman Street", + "College Hill", + "Compter Passage", + "Cooper's Row", + "Copthall Avenue", + "Corbet Court", + "Cornhill", + "Cousin Lane", + "Cowper's Court", + "Crane Court", + "Creechurch Lane", + "Creed Court", + "Crescent", + "Cripplegate Street", + "Cromwell Highwalk", + "Crosby Square", + "Cross Keys Square", + "Cross Lane", + "Crosswall", + "Crown Court", + "Crown Office Row", + "Crutched Friars", + "Cullum Street", + "Cunard Place", + "Cursitor Street", + "Custom House Walk", + "Cutler Street", + "Dark House Walk", + "Dean's Court", + "Defoe Place", + "Devonshire Row", + "Distaff Lane", + "Doby Court", + "Dorset Buildings", + "Dowgate Hill", + "Drapers Gardens", + "Dukes Place", + "Dunster Court", + "Dyer's Buildings", + "Eastcheap", + "East Harding Street", + "East Passage", + "East Poultry Avenue", + "Eldon Street", + "Elm Court", + "Essex Court", + "Exchange Arcade", + "Falcon Court", + "Falcon Highwalk", + "Fann Street", + "Farringdon Street", + "Fen Court", + "Fetter Lane", + "Finch Lane", + "Finsbury Avenue", + "Fish Street Hill", + "Fishmongers Hall Wharf", + "Fleet Place", + "Fore Street", + "Fort Street", + "Foster Lane", + "Founders' Court", + "Fountain Court", + "Frederick's Place", + "French Ordinary Court", + "Friar Street", + "Friday Street", + "Frobisher Crescent", + "Fruiterers Passage", + "Furnival Street", + "Fye Foot Lane", + "Garden Court", + "Gardner's Lane", + "Garlick Hill", + "George Yard", + "Giltspur Street", + "Gloucester Court", + "Godliman Street", + "Golden Lane", + "Goldsmith Street", + "Goodman's Court", + "Gophir Lane", + "Goring Street", + "Goswell Road", + "Gough Square", + "Gracechurch Street", + "Grand Avenue", + "Grant's Quay Wharf", + "Gravel Lane", + "Great Bell Alley", + "Great Eastern Walk", + "Great New Street", + "Great St Helen's", + "Great St Thomas Apostle", + "Great Swan Alley", + "Great Tower Street", + "Great Trinity Lane", + "Great Winchester Street", + "Green Arbour Court", + "The Green Yard", + "Gresham Street", + "Greyfriars Passage", + "Greystoke Place", + "Grocer's Hall Court", + "Groveland Court", + "Guildhall Buildings", + "Guinness Court", + "Gunpowder Square", + "Gutter Lane", + "Half Moon Court", + "Hammett Street", + "Hanging Sword Alley", + "Hanseatic Walk", + "Hare Place", + "Harp Alley", + "Harp Lane", + "Harrow Place", + "Hart Street", + "Hartshorn Alley", + "Haydon Street", + "Hayne Street", + "Hen", + "Heneage Lane", + "High Holborn", + "High Timber Street", + "Hind Court", + "Hogarth Court", + "Honey Lane", + "Hood Court", + "Hope Square", + "Hosier Lane", + "Houndsditch", + "Huggin Court", + "Hutton Street", + "Idol Lane", + "India Street", + "Inner Temple Lane", + "Ireland Yard", + "Ironmonger Lane", + "Jewry Street", + "John Carpenter Street", + "John Milton Passage", + "John Trundle Highwalk", + "John Wesley Highwalk", + "Johnsons Court", + "Keats Place", + "Kennett Wharf Lane", + "Kinghorn Street", + "Kingscote Street", + "King Street", + "King Edward Street", + "King William Street", + "King's Arms Yard", + "King's Bench Walk", + "Knightrider Court", + "Lakeside Terrace", + "Lambert Jones Mews", + "Lambeth Hill", + "Langthorn Court", + "Lauderdale Place", + "Laurence Pountney Hill", + "Lawrence Lane", + "Leadenhall Market", + "Lime Street", + "Limeburner Lane", + "Lindsey Street", + "Little Britain", + "Little Somerset Street", + "Liverpool Street", + "Lloyd's Avenue", + "Lombard Court", + "Lombard Street", + "London Bridge", + "London Street", + "London Wall", + "Long Lane", + "Lothbury", + "Lovat Street", + "Love Lane", + "Lower Thames Street", + "Ludgate Broadway", + "Mac's Place", + "Magpie Alley", + "Mansell Street", + "Mansion House Place", + "Mark Lane", + "Martin Lane", + "Mason's Avenue", + "Middle Street", + "Middlesex Passage", + "Middlesex Street", + "Middle Temple Lane", + "Milk Street", + "Millennium Bridge", + "Milton Court", + "Mincing Lane", + "Minerva Walk", + "Miniver Place", + "Minories", + "Minster Court", + "Mitre Square", + "Modern Court", + "Monkwell Square", + "Montague Street", + "Monument Street", + "Moorfields", + "Moorgate", + "Moor Lane", + "Muscovy Street", + "Nettleton Court", + "Nevill Lane", + "New Bell Yard", + "New Bridge Street", + "Newbury Street", + "Newcastle Close", + "Newcastle Court", + "New Change", + "New Court", + "Newgate Street", + "Newman's Court", + "New Street", + "New Union Street", + "Nicholas Lane", + "Noble Street", + "Northumberland Alley", + "Norton Folgate", + "Norwich Street", + "Nun Court", + "Oat Lane", + "Octagon Arcade", + "Old Bailey", + "Old Billingsgate Walk", + "Old Jewry", + "Old Mitre Court", + "Old Seacole Lane", + "Old Watermen's Walk", + "Outwich Street", + "Oystergate Walk", + "Oxford Court", + "Pageantmaster Court", + "Pancras Lane", + "Panyer Alley", + "Paternoster Lane", + "Paul's Walk", + "Pemberton Row", + "Pepys Street", + "Peterborough Court", + "Peter's Hill", + "Petty Wales", + "Philpot Lane", + "Pilgrim Street", + "Pindar Street", + "Pinner's Passage", + "Plaisterers Highwalk", + "Plantation Lane", + "Playhouse Yard", + "Pleydell Court", + "Plough Court", + "Plough Place", + "Plumtree Court", + "Pope's Head Alley", + "Poppins Court", + "Portsoken Street", + "Post Office Court", + "Poultry", + "Priest's Court", + "Primrose Hill", + "Primrose Street", + "Prince's Street", + "Printers Inn Court", + "Printer Street", + "Priory Court", + "Prudent Passage", + "Pudding Lane", + "Puddle Dock", + "Pump Court", + "Quality Court", + "Queenhithe", + "Queen Isabella Way", + "Queens Head Passage", + "Queen Street", + "Queen Victoria Street", + "Rangoon Street", + "Red Lion Court", + "Regent Street", + "Rising Sun Court", + "Robin Hood Court", + "Rolls Buildings", + "Rood Lane", + "Ropemaker Street", + "Rose Alley", + "Rose", + "Rose Street", + "Royal Exchange Avenue", + "Russia Row", + "St Alphage Garden", + "St Andrew Street", + "St Andrew's Hill", + "St Benet's Place", + "St Botolph Row", + "St Clare Street", + "St Dunstan's Alley", + "St Dunstan's Court", + "St Georges Court", + "St Giles Terrace", + "St James's Passage", + "St Katherine's Row", + "St Margaret's Close", + "St Martin's le Grand", + "St Mary at Hill", + "St Mary Axe", + "St Michael's Alley", + "St Mildred's Court", + "St Olave's Court", + "St Paul's Churchyard", + "St Peter's Alley", + "St Swithins Lane", + "Salisbury Court", + "Salters Court", + "Salter's Hall Court", + "Sandy's Row", + "Saracens Head Yard", + "Savage Gardens", + "Scott's Lane", + "Seething Lane", + "Serjeants Inn", + "Sermon Lane", + "Shafts Court", + "Sherborne Lane", + "Ship Tavern Passage", + "Shoe Lane", + "Shorter Street", + "Silk Street", + "Sise Lane", + "Skinners Lane", + "Smithfield Street", + "Snow Hill", + "Southampton Buildings", + "South Place", + "Southwark Bridge", + "Speed Highwalk", + "Staining Lane", + "Staple Inn", + "Star Alley", + "Stationer's Hall Court", + "Steelyard Passage", + "Stew Lane", + "Stonecutter Street", + "Stone House Court", + "Stoney Lane", + "Suffolk Lane", + "Sugar Bakers Court", + "Sugar Quay Walk", + "Sun Court", + "Sun Street", + "Swan Lane", + "Swedeland Court", + "Talbot Court", + "Tallis Street", + "Telegraph Street", + "Temple Avenue", + "The Terrace", + "Thavies Inn", + "Thomas More Highwalk", + "Threadneedle Street", + "Three Barrels Walk", + "Three Cranes Walk", + "Three Nun Court", + "Three Quays Walk", + "Throgmorton Avenue", + "Tokenhouse Yard", + "Took's Court", + "Tower Hill Terrace", + "Tower Royal", + "Trig Lane", + "Trinity Square", + "Trump Street", + "Tudor Street", + "Turnagain Lane", + "Undershaft", + "Union Court", + "Victoria Avenue", + "Victoria Embankment", + "Vine Street", + "Vintners Court", + "Viscount Street", + "Waithman Street", + "Walbrook", + "Wardrobe Place", + "Warwick Lane", + "Watergate", + "Water Lane", + "Watling Court", + "Well Court", + "Whalebone Court", + "Whitecross Place", + "Whitecross Street", + "Whitefriars Street", + "White Hart Court", + "White Hart Street", + "White Horse Yard", + "White Kennett Street", + "White Lion Court", + "White Lion Hill", + "White Lyon Court", + "Whittington Avenue", + "Widegate Street", + "Willoughby Highwalk", + "Wilson Street", + "Wine Office Court", + "Wood Street", + "Wormwood Street", + "Wrestler's Court" +]; + +var laneNames; // Complete this line + +console.log(laneNames); +console.log(laneNames.length); + +/* EXPECTED OUTPUT +---------------------- +[ 'Abchurch Lane', + 'Allhallows Lane', + ... many more ... + 'Water Lane' ] +74 +*/ diff --git a/week-4/Homework/extra/extra-homework.md b/week-4/Homework/extra/extra-homework.md index 4aa5066a0..00b116e4e 100644 --- a/week-4/Homework/extra/extra-homework.md +++ b/week-4/Homework/extra/extra-homework.md @@ -6,17 +6,6 @@ Click "ATTEMPT" to test your solution. Exercises: -- [Fix my Method](https://www.codewars.com/kata/558710234f02dcc4a8000005) -- [Regular Ball Super Ball](https://www.codewars.com/kata/53f0f358b9cb376eca001079/train/javascript) - -## Reading - -1.['You Don't Know JS: this & Object Prototypes' - Chapter 3, 'Objects'](https://github.com/getify/You-Dont-Know-JS/blob/1st-ed/this%20%26%20object%20prototypes/ch3.md) - -2. Eloquent JavaScript Chapter 4 - 'Data Structures: Objects and Arrays': https://eloquentjavascript.net/04_data.html -3. Eloquent JavaScript Chapter 6 - 'The Secret Life of Objects': https://eloquentjavascript.net/06_object.html - -## Viewing - -1. [Methods and 'this' keyword in JavaScript](https://www.youtube.com/watch?v=0wN-L9CG3y0) -2. [Modern JavaScript Tutorial #5 - Objects](https://www.youtube.com/watch?v=X0ipw1k7ygU) +- [Hackerwars](https://www.codewars.com/kata/crash-override/train/javascript) +- [Job Matching #1](https://www.codewars.com/kata/56c22c5ae8b139416c00175d/train/javascript) +- [Split the Bill](https://www.codewars.com/kata/5641275f07335295f10000d0/train/javascript) diff --git a/week-4/Homework/mandatory/1-food.js b/week-4/Homework/mandatory/1-food.js new file mode 100644 index 000000000..58f525a12 --- /dev/null +++ b/week-4/Homework/mandatory/1-food.js @@ -0,0 +1,51 @@ +let myFavFood = { + name: "falafel wrap", + isVeggie: true, + caloriesPerPortion: 550, + ingredients: ["chickpeas", "cumin", "oil", "sesame seeds", "tahini sauce"], + takeAway: { + name: "falafel to go", + address: "Hope St. Glasgow", + }, +}; + +// 1. console.log() the name of myFavFood + +console.log("Favorite food is " + myFavFood.name); + +// 2. Declare a function "getTakeAwayAddress" that accepts "food" as a parameter +// and returns the address of where to buy it + +function getTakeAwayAddress(food) { + // write code here +} + +console.log("I can buy my favorite food from " + getTakeAwayAddress(myFavFood)); + +// 3. Declare a function "isVeggie" that accepts "food" as a parameter +// and returns true if it's vegetarian, or false if not + +function isVeggie(food) { + // write code here +} + +console.log("Is my favorite vegetarian? " + isVeggie(food)); + +// 3. Declare a function "isLowCalorie" that accepts "food" as a parameter +// and returns true if it has less than 600 calories, or false otherwise +// write your own console.log() that calls the function to test it, as in the examples above! +// no example code is provided here! + +//--------------------------------------- + +// 3. Declare a function "isSafeForNutAllergies" that accepts "food" as a parameter +// and returns false if it found the word "sesame" in the ingredients, or true otherwise + +function isSafeForNutAllergies(food) { + //write code here +} + +console.log( + "Is my favorite food nut allergy safe? ", + isSafeForNutAllergies(myFavFood) +); diff --git a/week-4/Homework/mandatory/1-freecodecamp.md b/week-4/Homework/mandatory/1-freecodecamp.md deleted file mode 100644 index a05de7191..000000000 --- a/week-4/Homework/mandatory/1-freecodecamp.md +++ /dev/null @@ -1,20 +0,0 @@ -## FreeCodeCamp Lessons - -Complete all 26 of the 'Object Oriented Programming' lessons on FreeCodeCamp at https://www.freecodecamp.org/learn - -- Introduction to the Object Oriented Programming Challenges -- Create a Basic JavaScript Object -- Use Dot Notation to Access the Properties of an Object -- Create a Method on an Object -- Make Code More Reusable with the this Keyword -- Define a Constructor Function -- Use a Constructor to Create Objects -- Extend Constructors to Receive Arguments -- Verify an Object's Constructor with instanceof -- Understand Own Properties -- Use Prototype Properties to Reduce Duplicate Code -- Iterate Over All Properties -- Understand the Constructor Property -- Change the Prototype to a New Object -- Remember to Set the Constructor Property when Changing the Prototype -- Understand Where an Object’s Prototype Comes From diff --git a/week-4/Homework/mandatory/2-writers.js b/week-4/Homework/mandatory/2-writers.js index 974a173aa..a071ef0bb 100644 --- a/week-4/Homework/mandatory/2-writers.js +++ b/week-4/Homework/mandatory/2-writers.js @@ -14,29 +14,29 @@ let writers = [ lastName: "Woolf", occupation: "writer", age: 59, - alive: false + alive: false, }, { firstName: "Zadie", lastName: "Smith", occupation: "writer", age: 41, - alive: true + alive: true, }, { firstName: "Jane", lastName: "Austen", occupation: "writer", age: 41, - alive: false + alive: false, }, { firstName: "bell", lastName: "hooks", occupation: "writer", age: 64, - alive: true - } + alive: true, + }, ]; /* diff --git a/week-4/Homework/mandatory/3-translator.js b/week-4/Homework/mandatory/3-translator.js new file mode 100644 index 000000000..8cd13d915 --- /dev/null +++ b/week-4/Homework/mandatory/3-translator.js @@ -0,0 +1,47 @@ +const languages = { + english: "Welcome", + czech: "Vitejte", + danish: "Velkomst", + dutch: "Welkom", + estonian: "Tere tulemast", + finnish: "Tervetuloa", + flemish: "Welgekomen", + french: "Bienvenue", + german: "Willkommen", + irish: "Failte", + italian: "Benvenuto", + latvian: "Gaidits", + lithuanian: "Laukiamas", + polish: "Witamy", + spanish: "Bienvenido", + swedish: "Valkommen", + welsh: "Croeso", +}; + +console.log(languages.english); +console.log(languages["english"]); +/* +Write a 'greet' function that takes a parameter 'language' (always a string), +and returns the greeting for that language - if it exists in your "languages" object. + +It should default to English if the language is not in your object of languages, +or in the event of an invalid input. +*/ + +function greet(language) { + //write your code here + return languages[language]; +} + +/* +Test your function works correctly calling it inside a console.log(), for each one of these cases: + +1. pass it a valid lowercase language + +For example: console.log(greet("irish")); + +2. pass it a valid uppercase language +3. pass it a language that doesn't exist in the object +4. pass it an invalid string (something that is not even a language) + +*/ diff --git a/week-4/Homework/mandatory/3-water-bottle.js b/week-4/Homework/mandatory/3-water-bottle.js deleted file mode 100644 index cb8041140..000000000 --- a/week-4/Homework/mandatory/3-water-bottle.js +++ /dev/null @@ -1,41 +0,0 @@ -/* -Create an object that acts like a water bottle. -It will need a volume key to store how full or empty the bottle is. -It will be 100 when full and 0 when empty. -Give your water bottle methods for filling it up, -drinking some of it, and emptying it. - -We made a start on this for you here: -*/ - -let bottle = { - volume: 0, - fill: function() { - // calling this function should make you bottles volume = 100; - }, - drink: function() { - // calling this function should decrease your bottles volume by 10; - }, - empty: function() { - // this function should return true if your bottles volume = 0 - } -}; - -/* ---TIP-- - -Remember that for changing properties on the current object inside one of its -methods you can refer to it by its variable name: `bottle`. - -Once you have completed your object run the following and see if your answer -matches the expected result at the bottom :) -*/ - -bottle.fill(); -bottle.drink(); -bottle.drink(); -bottle.drink(); -if (!bottle.empty()) { - console.log(`bottles volume = ${bottle.volume}`); -} -console.log("Above volume should be: 70"); diff --git a/week-4/Homework/mandatory/4-groceries.js b/week-4/Homework/mandatory/4-groceries.js deleted file mode 100644 index 2b34cdb53..000000000 --- a/week-4/Homework/mandatory/4-groceries.js +++ /dev/null @@ -1,12 +0,0 @@ -// You're going shopping, and you need a shopping list. -// 1. Update your groceryList with the items you need: Potatoes, Orange Juice and Rice. -// 2. Loop through the groceryList object to gather the item properties into the groceriesToBuy array. -// 3. Then use console.log() to print out the list. It should print ['Potatoes', 'Orange Juice', 'Rice'] - -let groceriesToBuy = []; - -let groceryList = { - item1: "", - item2: "", - item3: "" -}; diff --git a/week-4/Homework/mandatory/5-codewars.md b/week-4/Homework/mandatory/5-codewars.md deleted file mode 100644 index cc5c8e86b..000000000 --- a/week-4/Homework/mandatory/5-codewars.md +++ /dev/null @@ -1,17 +0,0 @@ -## Reading - -- [Understanding JavaScript Constructors](https://css-tricks.com/understanding-javascript-constructors/) - -## CodeWars Exercises - -Complete the following CodeWars exercises. Go to the webpages below and follow the instructions there. - -Click "ATTEMPT" to test your solution. - -Exercises: - -- [Training JS #5: Basic data types--Object](https://www.codewars.com/kata/571f1eb77e8954a812000837/train/javascript) -- [Welcome!](https://www.codewars.com/kata/welcome/train/javascript) -- [Crash Override](https://www.codewars.com/kata/crash-override/train/javascript) -- [Job Matching #1](https://www.codewars.com/kata/56c22c5ae8b139416c00175d/train/javascript) -- [Split the Bill](https://www.codewars.com/kata/5641275f07335295f10000d0/train/javascript) diff --git a/week-5/Homework/mandatory/3-project/js/main.js b/week-4/IT-WORKED.md similarity index 100% rename from week-5/Homework/mandatory/3-project/js/main.js rename to week-4/IT-WORKED.md diff --git a/week-4/InClass/D-methods/README.md b/week-4/InClass/D-methods/README.md index 7c65fe76e..fee6a85a2 100644 --- a/week-4/InClass/D-methods/README.md +++ b/week-4/InClass/D-methods/README.md @@ -1,69 +1,19 @@ ### Object methods -Besides having specific properties, objects in the real world can also do things. For example, a computer can display something on the screen, a person can say their names etc... In Javascript, we do this using 'methods'. A method is a function attached to a particular object. You have already used some predefined methods before, for example *toUpperCase()* on a string or *filter()* on an array. +Besides having specific properties, objects in the real world can also do things. For example, a computer can display something on the screen, a person can say their names etc... In Javascript, we do this using 'methods'. A method is a function attached to a particular object. You have already used some predefined methods before, for example _toUpperCase()_ on a string or _filter()_ on an array. ```js let athlete = { - name: 'Usain Bolt', - goldMedals: 25, - sayHi: function() { - return "Hi everybody!"; - } + name: "Usain Bolt", + goldMedals: 25, + sayHi: function () { + return "Hi everybody!"; + }, }; ``` -How do we call this method? +How do we call this method? ```js athlete.sayHi(); // returns "Hi everybody!" ``` - -An object method can also rely on the other properties of the object to do more complex calculation. To reference the current object in the body of the method, we will use the keyword *this*. Let's take an example. - -```js -let athlete = { - name: 'Usain Bolt', - goldMedals: 25, - sayName: function() { - return "My name is " + this.name; - } -}; - -athlete.sayName(); // returns "My name is Usain Bolt" -``` - -Knowing this, you can have methods which modify existing properties of your object. - -```js -let athlete = { - name: 'Usain Bolt', - goldMedals: 25, - winNewMedal: function() { - this.goldMedals = this.goldMedals + 1; - } -}; - -athlete.winNewMedal(); -console.log(athelete.goldMedals); // prints "26" -``` - -As methods are just functions attached to objects, they can also take parameters. - -```js -let athlete = { - name: 'Usain Bolt', - goldMedals: 25, - silverMedals: 7, - winNewMedal: function(medal) { - if (medal === "gold") { - this.goldMedals = this.goldMedals + 1; - } else { - this.silverMedals = this.silverMedals + 1; - } - } -}; - -athlete.winNewMedal("silver"); -console.log(athlete.goldMedals); // prints "25" -console.log(athlete.silverMedals); // prints "8" -``` \ No newline at end of file diff --git a/week-4/InClass/D-methods/exercise-2.js b/week-4/InClass/D-methods/exercise-2.js index 8e993fc69..acc52024e 100644 --- a/week-4/InClass/D-methods/exercise-2.js +++ b/week-4/InClass/D-methods/exercise-2.js @@ -1,18 +1,17 @@ /* A person named Alice is defined below. Add a method "sayName" so this person can say their own name. -Hint: use 'this' keyword to access the name property. */ - let person = { - name: "Alice", - age: 25 + name: "Alice", + age: 25, }; - /* DO NOT EDIT ANYTHING BELOW THIS LINE */ -console.log(`Expected result: 'My name is Alice'. Actual result: ${person.sayName()}`); \ No newline at end of file +console.log( + `Expected result: 'My name is Alice'. Actual result: ${person.sayName()}` +); diff --git a/week-4/InClass/D-methods/exercise-3.js b/week-4/InClass/D-methods/exercise-3.js deleted file mode 100644 index be237483b..000000000 --- a/week-4/InClass/D-methods/exercise-3.js +++ /dev/null @@ -1,28 +0,0 @@ -/* -The following code contains syntax errors - try and fix them! -Once you fix them, run this file, it should output the correct values! -*/ - - -let person = { - name: "Alice", - age: 25, - currentAddress: "Glasgow", - changeAddress: (newAddress) { - currentAddress = newAddress; - }, - celebrateBirthday: function { - that.age = that.age + 1; - } -}; - - -/* -DO NOT EDIT ANYTHING BELOW THIS LINE -*/ - -person.changeAddress("Edinburgh"); -console.log(`Expected result: Edinburgh. Actual result: ${person.currentAddress}`); - -person.celebrateBirthday(); -console.log(`Expected result: 26. Actual result: ${person.age}`); diff --git a/week-4/InClass/D-methods/exercise-4.js b/week-4/InClass/D-methods/exercise-4.js deleted file mode 100644 index d89214a72..000000000 --- a/week-4/InClass/D-methods/exercise-4.js +++ /dev/null @@ -1,19 +0,0 @@ -/* -Alice has a list of good friends. -Define a method "makeFriend" to add a new friend to her list. -*/ - - -let person = { - name: "Alice", - friends: ["John", "Nina"] -}; - - -/* -DO NOT EDIT ANYTHING BELOW THIS LINE -*/ - -person.makeFriend("Bob"); - -console.log(`Expected result: 'John,Nina,Bob'. Actual result: ${person.friends}`); \ No newline at end of file diff --git a/week-4/InClass/D-methods/exercise-5.js b/week-4/InClass/D-methods/exercise-5.js deleted file mode 100644 index dcd198c47..000000000 --- a/week-4/InClass/D-methods/exercise-5.js +++ /dev/null @@ -1,43 +0,0 @@ -/* -A coffee machine is defined below. -One can buy three different coffees. -Complete the methods "insertMoney" and "getCoffee" to match the expected result. - -insertMoney takes an amount in parameter to add money in the coffee machine. -getCoffee takes a coffee type in parameter and dispends the selected coffee -only if the inserted amount is greater or equal than the price of the coffee! -*/ - -let coffeeMachine = { - brand: "Super Coffee", - prices: { - cappuccino: 2.40, - blackCoffee: 1.50, - flatWhite: 3.00 - }, - insertedAmount: 0, - insertMoney: function (amount) { - - }, - getCoffee: function (coffee) { - - } -}; - - -/* -DO NOT EDIT ANYTHING BELOW THIS LINE -*/ - -coffeeMachine.insertMoney(2.40); -console.log(`Expected result: 'Please take your cappuccino'. Actual result: ${coffeeMachine.getCoffee('cappuccino')}`); - -coffeeMachine.insertMoney(1.50); -console.log(`Expected result: 'Please take your blackCoffee'. Actual result: ${coffeeMachine.getCoffee('blackCoffee')}`); - -coffeeMachine.insertMoney(4.00); -console.log(`Expected result: 'Please take your flatWhite'. Actual result: ${coffeeMachine.getCoffee('flatWhite')}`); - -coffeeMachine.insertMoney(2.40); -console.log(`Expected result: 'Sorry you don't have enough money for a flatWhite'. Actual result: ${coffeeMachine.getCoffee('flatWhite')}`); - diff --git a/week-4/InClass/E-arrays-of-objects/exercise-2.js b/week-4/InClass/E-arrays-of-objects/exercise-2.js index c2259dd23..43a66a6b0 100644 --- a/week-4/InClass/E-arrays-of-objects/exercise-2.js +++ b/week-4/InClass/E-arrays-of-objects/exercise-2.js @@ -32,25 +32,44 @@ let destination4 = { transportations: ["plane", "ferry"] }; -let travelDestinations = [destination1, destination2, destination3, destination4]; +let travelDestinations = [ + destination1, + destination2, + destination3, + destination4 +]; -/* -DO NOT EDIT ANYTHING ABOVE THIS LINE -WRITE YOUR CODE BELOW -*/ +// [ +// {destinationName: "Dublin", distanceKms: 350}, +// {destinationName: "Dublin", distanceKms: 350}, +// {destinationName: "Dublin", distanceKms: 350}, +// ] +// ["Dublin", "Paris", "Edinburgh"] -let destinationNamesWithin500Kms = // Complete here -let destinationNameReachableByFerry = // Complete here +// 1. Print in the console +// 2. all the destination names +// 3. more than 300 kms far away and reachable by train. -let destinationNamesMoreThan300KmsAwayByTrain = // Complete here (PRINT THE RESULT IN THE CONSOLE USING FOREACH) +function isReachable(destination) { + let isFar = destination.distanceKms > 300; + let trainReachable = destination.transportations.includes("train"); + return isFar && trainReachable; +} +let reachableDestinations = travelDestinations.filter(isReachable); -/* -DO NOT EDIT ANYTHING BELOW THIS LINE -*/ +function transformDestination(destination) { + let destinationName = destination.destinationName; + return destinationName; +} + +let destinationNames = reachableDestinations.map(transformDestination); + + +function printToConsole(destinationName) { + console.log(destinationName); +} -console.log(`Question 1) Expected result: Edinburgh,Dublin, actual result: ${destinationNamesWithin500Kms}`); -console.log(`Question 2) Expected result: Dublin, actual result: ${destinationNameReachableByFerry}`); -console.log(`Question 3) Expected result: London,Paris, actual result: ${destinationNamesMoreThan300KmsAwayByTrain}`); +destinationNames.forEach(printToConsole); diff --git a/week-4/InClass/E-arrays-of-objects/exercise-3.js b/week-4/InClass/E-arrays-of-objects/exercise-3.js index a1ec6916f..282765543 100644 --- a/week-4/InClass/E-arrays-of-objects/exercise-3.js +++ b/week-4/InClass/E-arrays-of-objects/exercise-3.js @@ -15,36 +15,36 @@ and returns the number of restaurants in this area. */ let restaurant1 = { - name: "Paesano", - totalSeats: 10, - numberOfCustomers: 8, - address: { - city: "Glasgow", - area: "center" - }, - menu: ["pizza", "calzone", "salad"] + name: "Paesano", + totalSeats: 10, + numberOfCustomers: 8, + address: { + city: "Glasgow", + area: "center", + }, + menu: ["pizza", "calzone", "salad"], }; let restaurant2 = { - name: "Ubiquitous Chip", - totalSeats: 20, - numberOfCustomers: 10, - address: { - city: "Glasgow", - area: "west" - }, - menu: ["salad", "chocolate cake", "roast lamb"] + name: "Ubiquitous Chip", + totalSeats: 20, + numberOfCustomers: 10, + address: { + city: "Glasgow", + area: "west", + }, + menu: ["salad", "chocolate cake", "roast lamb"], }; let restaurant3 = { - name: "Monkeyz", - totalSeats: 15, - numberOfCustomers: 8, - address: { - city: "Glasgow", - area: "center" - }, - menu: ["stew", "chocolate cake", "panini"] + name: "Monkeyz", + totalSeats: 15, + numberOfCustomers: 8, + address: { + city: "Glasgow", + area: "center", + }, + menu: ["stew", "chocolate cake", "panini"], }; let restaurants = [restaurant1, restaurant2, restaurant3]; @@ -54,32 +54,24 @@ DO NOT EDIT ANYTHING ABOVE THIS LINE WRITE YOUR CODE BELOW */ - -let restaurantFinderApplication = { - applicationName: "Restaurant Finder", - applicationVersion: "1.0", - restaurants: restaurants, - findAvailableRestaurants: function (numberOfPeople) { - // Complete here - }, - findRestaurantServingDish: function (dishName) { - // Complete here - }, - countNumberOfRestaurantsInArea: function (area) { - // Complete here - } -}; - - /* DO NOT EDIT ANYTHING BELOW THIS LINE */ -let restaurantsAvailableFor5People = restaurantFinderApplication.findAvailableRestaurants(5); -console.log(`Find available restaurants for 5 people: Expected result: Ubiquitous Chip,Monkeyz, actual result: ${restaurantsAvailableFor5People}`); - -let restaurantsServingSalad = restaurantFinderApplication.findRestaurantServingDish("salad"); -console.log(`Find restaurants serving salad: Expected result: Paesano,Ubiquitous Chip, actual result: ${restaurantsServingSalad}`); - -let numberOfRestaurantsInCityCentre = restaurantFinderApplication.countNumberOfRestaurantsInArea("center"); -console.log(`Number of restaurants in city centre: Expected result: 2, actual result: ${numberOfRestaurantsInCityCentre}`); +let restaurantsAvailableFor5People = findAvailableRestaurants(restaurants, 5); +console.log( + `Find available restaurants for 5 people: Expected result: Ubiquitous Chip,Monkeyz, actual result: ${restaurantsAvailableFor5People}` +); + +let restaurantsServingSalad = findRestaurantServingDish(restaurants, "salad"); +console.log( + `Find restaurants serving salad: Expected result: Paesano,Ubiquitous Chip, actual result: ${restaurantsServingSalad}` +); + +let numberOfRestaurantsInCityCentre = countNumberOfRestaurantsInArea( + restaurants, + "center" +); +console.log( + `Number of restaurants in city centre: Expected result: 2, actual result: ${numberOfRestaurantsInCityCentre}` +); diff --git a/week-4/InClass/G-loop-through-objects/exercise1.js b/week-4/InClass/G-loop-through-objects/exercise1.js new file mode 100644 index 000000000..6eec1d838 --- /dev/null +++ b/week-4/InClass/G-loop-through-objects/exercise1.js @@ -0,0 +1,17 @@ +let kitten1 = { + name: "Fluffy", + weeksOld: 2, +}; + +let kitten2 = { + name: "Megatron", + weeksOld: 1, +}; + +let kittens = [kitten1, kitten2]; + +function getName(kitten) { + return kitten.name.length === 5; +} + +kittens.map(getName); // should return ["Fluffy", "Megatron", "Billy"] diff --git a/week-5/Homework/mandatory/1-study/study.md b/week-5/Homework/extra/1-study/study.md similarity index 100% rename from week-5/Homework/mandatory/1-study/study.md rename to week-5/Homework/extra/1-study/study.md diff --git a/week-5/Homework/mandatory/4-practice/practice-codewars.md b/week-5/Homework/extra/2-practice/practice-codewars.md similarity index 100% rename from week-5/Homework/mandatory/4-practice/practice-codewars.md rename to week-5/Homework/extra/2-practice/practice-codewars.md diff --git a/week-5/Homework/extra/extra-homework.md b/week-5/Homework/extra/3-extra/extra-homework.md similarity index 100% rename from week-5/Homework/extra/extra-homework.md rename to week-5/Homework/extra/3-extra/extra-homework.md diff --git a/week-5/Homework/mandatory/1-exercises/assets/design_of_things.jpeg b/week-5/Homework/mandatory/1-exercises/assets/design_of_things.jpeg new file mode 100644 index 000000000..fdceb5cd1 Binary files /dev/null and b/week-5/Homework/mandatory/1-exercises/assets/design_of_things.jpeg differ diff --git a/week-5/Homework/mandatory/1-exercises/assets/most_human_human.jpeg b/week-5/Homework/mandatory/1-exercises/assets/most_human_human.jpeg new file mode 100644 index 000000000..b92aa356d Binary files /dev/null and b/week-5/Homework/mandatory/1-exercises/assets/most_human_human.jpeg differ diff --git a/week-5/Homework/mandatory/1-exercises/assets/pragmatic_programmer.jpeg b/week-5/Homework/mandatory/1-exercises/assets/pragmatic_programmer.jpeg new file mode 100644 index 000000000..b8d6b03b6 Binary files /dev/null and b/week-5/Homework/mandatory/1-exercises/assets/pragmatic_programmer.jpeg differ diff --git a/week-5/Homework/mandatory/2-exercises/exercises.js b/week-5/Homework/mandatory/1-exercises/exercises.js similarity index 78% rename from week-5/Homework/mandatory/2-exercises/exercises.js rename to week-5/Homework/mandatory/1-exercises/exercises.js index 174c5db04..09ed09252 100644 --- a/week-5/Homework/mandatory/2-exercises/exercises.js +++ b/week-5/Homework/mandatory/1-exercises/exercises.js @@ -24,7 +24,7 @@ function exerciseOne(arrayOfPeople) { * All of your HTML should go inside the Div tag with the id "content". * */ -function exerciseTwo(shopping) { +function exerciseTwo(shoppingItems) { //Write your code in here } @@ -35,17 +35,20 @@ function exerciseTwo(shopping) { { title: "The Design of Everyday Things", author: "Don Norman", - alreadyRead: false + alreadyRead: false, + coverImageUrl: "assets/design_of_things.jpeg" }, { title: "The Most Human Human", author: "Brian Christian", - alreadyRead: true + alreadyRead: true, + coverImageUrl: "assets/most_human_human.jpeg" }, { title: "The Pragmatic Programmer", author: "Andrew Hunt", - alreadyRead: true + alreadyRead: true, + coverImageUrl: "assets/pragmatic_programmer.jpeg" } ]; @@ -74,7 +77,7 @@ function exerciseThree(books) { let people = [ { name: "Chris", job: "Teacher" }, { name: "Joanna", job: "Student" }, - { name: "Boris", job: "Prime Minister" } + { name: "Boris", job: "Prime Minister" }, ]; exerciseOne(people); @@ -87,18 +90,21 @@ const books = [ { title: "The Design of Everyday Things", author: "Don Norman", - alreadyRead: false + alreadyRead: false, + coverImageUrl: "assets/design_of_things.jpeg", }, { title: "The Most Human Human", author: "Brian Christian", - alreadyRead: true + alreadyRead: true, + coverImageUrl: "assets/most_human_human.jpeg", }, { title: "The Pragmatic Programmer", author: "Andrew Hunt", - alreadyRead: true - } + alreadyRead: true, + coverImageUrl: "assets/pragmatic_programmer.jpeg", + }, ]; exerciseThree(books); diff --git a/week-5/Homework/mandatory/2-exercises/index.html b/week-5/Homework/mandatory/1-exercises/index.html similarity index 100% rename from week-5/Homework/mandatory/2-exercises/index.html rename to week-5/Homework/mandatory/1-exercises/index.html diff --git a/week-5/Homework/mandatory/2-exercises/style.css b/week-5/Homework/mandatory/1-exercises/style.css similarity index 100% rename from week-5/Homework/mandatory/2-exercises/style.css rename to week-5/Homework/mandatory/1-exercises/style.css diff --git a/week-5/Homework/mandatory/3-project/README.md b/week-5/Homework/mandatory/2-project/README.md similarity index 98% rename from week-5/Homework/mandatory/3-project/README.md rename to week-5/Homework/mandatory/2-project/README.md index 5caa8a338..f1cf9ec91 100644 --- a/week-5/Homework/mandatory/3-project/README.md +++ b/week-5/Homework/mandatory/2-project/README.md @@ -28,7 +28,7 @@ Here's an example of how the website should look for the blue button: ![Blue button example](images/blue_clicked.png) -## Part 2 +## Part 2 - VERY BONUS BONUS Just below the buttons, there's a form called **Register with us**. diff --git a/week-5/Homework/mandatory/3-project/images/blue_clicked.png b/week-5/Homework/mandatory/2-project/images/blue_clicked.png similarity index 100% rename from week-5/Homework/mandatory/3-project/images/blue_clicked.png rename to week-5/Homework/mandatory/2-project/images/blue_clicked.png diff --git a/week-5/Homework/mandatory/3-project/images/header-bike.jpg b/week-5/Homework/mandatory/2-project/images/header-bike.jpg similarity index 100% rename from week-5/Homework/mandatory/3-project/images/header-bike.jpg rename to week-5/Homework/mandatory/2-project/images/header-bike.jpg diff --git a/week-5/Homework/mandatory/3-project/index.html b/week-5/Homework/mandatory/2-project/index.html similarity index 100% rename from week-5/Homework/mandatory/3-project/index.html rename to week-5/Homework/mandatory/2-project/index.html diff --git a/week-5/Homework/mandatory/2-project/js/main.js b/week-5/Homework/mandatory/2-project/js/main.js new file mode 100644 index 000000000..e69de29bb diff --git a/week-5/Homework/mandatory/3-project/styles/style.css b/week-5/Homework/mandatory/2-project/styles/style.css similarity index 100% rename from week-5/Homework/mandatory/3-project/styles/style.css rename to week-5/Homework/mandatory/2-project/styles/style.css diff --git a/week-5/Homework/mandatory/0-khanacademy/khanacademy.md b/week-5/Homework/mandatory/3-learning-khanacademy/khanacademy.md similarity index 100% rename from week-5/Homework/mandatory/0-khanacademy/khanacademy.md rename to week-5/Homework/mandatory/3-learning-khanacademy/khanacademy.md diff --git a/week-5/InClass/A-dom-manipulation/exercise.js b/week-5/InClass/A-dom-manipulation/exercise.js index bb4f2e92b..717fb16f5 100644 --- a/week-5/InClass/A-dom-manipulation/exercise.js +++ b/week-5/InClass/A-dom-manipulation/exercise.js @@ -16,7 +16,6 @@ Write JavaScript below that logs: */ - /* Task 2 ====== @@ -24,7 +23,6 @@ Task 2 When a user clicks the 'ALERT' button, an alert box should pop up with the text "Thanks for visiting Bikes for Refugees!" */ - /* Task 3 ======= @@ -32,7 +30,6 @@ Task 3 Write JavaScript below that changes the background colour of the page when the 'Change colour' button is clicked. */ - /* Task 4 ====== @@ -40,11 +37,17 @@ Task 4 When a user clicks the 'Add some text' button, a new paragraph should be added below the buttons that says "Read more below." */ - - /* Task 5 ====== When the 'Larger links!' button is clicked, the text of all links on the page should increase. -*/ \ No newline at end of file +*/ + +/* +Task 6 +====== + +Using JavaScript, create an unordered list under the "Add" button. +When the "Add" button is pressed, get the value of the text box on its left, and add it to the list you created above. +*/ diff --git a/week-5/WEEK5-WORKED.md b/week-5/WEEK5-WORKED.md new file mode 100644 index 000000000..e69de29bb diff --git a/week-6/Homework/mandatory/3-slideshow/example-screenshots/example-level1.png b/week-6/Homework/extra/2-slideshow/example-screenshots/example-level1.png similarity index 100% rename from week-6/Homework/mandatory/3-slideshow/example-screenshots/example-level1.png rename to week-6/Homework/extra/2-slideshow/example-screenshots/example-level1.png diff --git a/week-6/Homework/mandatory/3-slideshow/example-screenshots/example-level2.png b/week-6/Homework/extra/2-slideshow/example-screenshots/example-level2.png similarity index 100% rename from week-6/Homework/mandatory/3-slideshow/example-screenshots/example-level2.png rename to week-6/Homework/extra/2-slideshow/example-screenshots/example-level2.png diff --git a/week-6/Homework/mandatory/3-slideshow/index.html b/week-6/Homework/extra/2-slideshow/index.html similarity index 100% rename from week-6/Homework/mandatory/3-slideshow/index.html rename to week-6/Homework/extra/2-slideshow/index.html diff --git a/week-6/Homework/mandatory/3-slideshow/slideshow.js b/week-6/Homework/extra/2-slideshow/slideshow.js similarity index 100% rename from week-6/Homework/mandatory/3-slideshow/slideshow.js rename to week-6/Homework/extra/2-slideshow/slideshow.js diff --git a/week-6/Homework/mandatory/3-slideshow/style.css b/week-6/Homework/extra/2-slideshow/style.css similarity index 100% rename from week-6/Homework/mandatory/3-slideshow/style.css rename to week-6/Homework/extra/2-slideshow/style.css diff --git a/week-6/Homework/mandatory/3-slideshow/task.md b/week-6/Homework/extra/2-slideshow/task.md similarity index 100% rename from week-6/Homework/mandatory/3-slideshow/task.md rename to week-6/Homework/extra/2-slideshow/task.md diff --git a/week-6/Homework/extra/2-slideshow-extra/task.md b/week-6/Homework/extra/3-slideshow-extra/task.md similarity index 100% rename from week-6/Homework/extra/2-slideshow-extra/task.md rename to week-6/Homework/extra/3-slideshow-extra/task.md diff --git a/week-6/InClass/DOM-practice/ada-lovelace.jpg b/week-6/Homework/mandatory/3-DOM-practice/ada-lovelace.jpg similarity index 100% rename from week-6/InClass/DOM-practice/ada-lovelace.jpg rename to week-6/Homework/mandatory/3-DOM-practice/ada-lovelace.jpg diff --git a/week-6/InClass/DOM-practice/finished-page.jpg b/week-6/Homework/mandatory/3-DOM-practice/finished-page.jpg similarity index 100% rename from week-6/InClass/DOM-practice/finished-page.jpg rename to week-6/Homework/mandatory/3-DOM-practice/finished-page.jpg diff --git a/week-6/InClass/DOM-practice/grace-hopper.jpg b/week-6/Homework/mandatory/3-DOM-practice/grace-hopper.jpg similarity index 100% rename from week-6/InClass/DOM-practice/grace-hopper.jpg rename to week-6/Homework/mandatory/3-DOM-practice/grace-hopper.jpg diff --git a/week-6/InClass/DOM-practice/index.html b/week-6/Homework/mandatory/3-DOM-practice/index.html similarity index 100% rename from week-6/InClass/DOM-practice/index.html rename to week-6/Homework/mandatory/3-DOM-practice/index.html diff --git a/week-6/InClass/DOM-practice/katherine-johnson.jpg b/week-6/Homework/mandatory/3-DOM-practice/katherine-johnson.jpg similarity index 100% rename from week-6/InClass/DOM-practice/katherine-johnson.jpg rename to week-6/Homework/mandatory/3-DOM-practice/katherine-johnson.jpg diff --git a/week-6/InClass/DOM-practice/main.js b/week-6/Homework/mandatory/3-DOM-practice/main.js similarity index 100% rename from week-6/InClass/DOM-practice/main.js rename to week-6/Homework/mandatory/3-DOM-practice/main.js diff --git a/week-6/InClass/DOM-practice/styles.css b/week-6/Homework/mandatory/3-DOM-practice/styles.css similarity index 100% rename from week-6/InClass/DOM-practice/styles.css rename to week-6/Homework/mandatory/3-DOM-practice/styles.css diff --git a/week-6/InClass/1-Async/exercise1.js b/week-6/InClass/1-Async/exercise1.js new file mode 100644 index 000000000..5c0134468 --- /dev/null +++ b/week-6/InClass/1-Async/exercise1.js @@ -0,0 +1,11 @@ +const greekGods = [ + "Aphrodite", + "Ares", + "Artemis", + "Athena", + "Poseidon", + "Zeus", +]; + +// 1. Console.log() the name of the first and second god in the list +// 2. Console.log() the name of the first god after 3 seconds, and the name of the second god after 1 second \ No newline at end of file diff --git a/week-6/InClass/Callbacks/exercise-1/exercise.js b/week-6/InClass/2-Callbacks/exercise-1/exercise.js similarity index 58% rename from week-6/InClass/Callbacks/exercise-1/exercise.js rename to week-6/InClass/2-Callbacks/exercise-1/exercise.js index 40f06b026..02fc93607 100644 --- a/week-6/InClass/Callbacks/exercise-1/exercise.js +++ b/week-6/InClass/2-Callbacks/exercise-1/exercise.js @@ -6,8 +6,7 @@ Task 1 Using setTimeout, change the background colour of the page after 5 seconds (5000 milliseconds). Task 2 -Update your code to make the colour change every 5 seconds to something different. Hint: try searching for setInterval. Complete the exercises in this CodePen +Update your code to make the colour change every 5 seconds to something different. Hint: try searching for setInterval. -Prefer to work on a codepen? https://codepen.io/makanti/pen/abOreLg ================ */ \ No newline at end of file diff --git a/week-6/InClass/Callbacks/exercise-1/index.html b/week-6/InClass/2-Callbacks/exercise-1/index.html similarity index 100% rename from week-6/InClass/Callbacks/exercise-1/index.html rename to week-6/InClass/2-Callbacks/exercise-1/index.html diff --git a/week-6/InClass/2-Callbacks/exercise-2/exercise.js b/week-6/InClass/2-Callbacks/exercise-2/exercise.js new file mode 100644 index 000000000..c1596fa1f --- /dev/null +++ b/week-6/InClass/2-Callbacks/exercise-2/exercise.js @@ -0,0 +1,57 @@ +/* +================ +Exercise 2 +---------- +================ +*/ +const movies = [ + { + title: "Color Out of Space", + haveWatched: true, + }, + { + title: "A Twelve-Year Night", + haveWatched: false, + }, + { + title: "The Whistlers", + haveWatched: true, + }, + { + title: "The Invisible Man", + haveWatched: false, + }, +]; + +function createDomMovie(movie) { + const movieInfo = document.createElement("p"); + movieInfo.innerText = `Title: ${movie.title}. Seen: ${movie.haveWatched}`; + const allMovies = document.querySelector("#all-movies"); + allMovies.appendChild(movieInfo); +} + +function reloadMovieList() { + const allMovies = document.querySelector("#all-movies"); + allMovies.innerHTML = ""; + movies.forEach(createDomMovie); +} + +reloadMovieList(); + +function addMovie() { + const loadingText = document.querySelector("#loading-text"); + const movieTitleInput = document.querySelector("#new-movie-input"); + const movieTitle = movieTitleInput.value; + + // Your task - write the code in this function: + // 1. The moment this function is called: + // - clear the input so it's empty + // - show the loading text (Hint: look inside index.html for some CSS classes you can use to show and hide this element) + // 2. after 4 seconds: + // - create a new movie object and add it to the "movies" array (make sure its "haveWatched" value is false) + // - hide the "loading text" + // - make sure the new movie shows up in the movie list +} + +const addMovieButton = document.querySelector("#add-movie-btn"); +addMovieButton.addEventListener("click", addMovie); diff --git a/week-6/InClass/2-Callbacks/exercise-2/index.html b/week-6/InClass/2-Callbacks/exercise-2/index.html new file mode 100644 index 000000000..178eced62 --- /dev/null +++ b/week-6/InClass/2-Callbacks/exercise-2/index.html @@ -0,0 +1,50 @@ + + + + + + CodeYourFuture - Callbacks + + + + + + + +
+
+

My movies

+
+

+ Saving your new movie... +

+
+
+ + + + + + diff --git a/week-6/InClass/Callbacks/exercise-2/exercise.js b/week-6/InClass/Callbacks/exercise-2/exercise.js deleted file mode 100644 index eca95957d..000000000 --- a/week-6/InClass/Callbacks/exercise-2/exercise.js +++ /dev/null @@ -1,70 +0,0 @@ -/* -================ -Exercise 2 ----------- -You are given the following list of movies - -Task 1 -Create a function called "showMovies" that -- iterates through the "movies" array and -- for each movie, it creates a

element with the movie title and director and append it to the #all-movies div. -- it sets the innerText of the #movies-number element to the total number of the movies in the array "movies" - -Task 2 -Amend your function above to only show movies after 1 second. Remember to use setTimeout to achieve that -Create a new function called "addMovie" -- it receives a movie object as an argument - your can create a new object for your favorite movie following using the "myMovies" objects as a guide -- it adds the new movie to the list of movies after 2 seconds. Remember to setTimeout to achieve that -Call addMovies to add the new movie to the list and then showMovies to see the movies added on the screen. -How many movies can you see on your page? - -Task 3 -Can you make sure the new movie you just added is showing on the screen? -TIP: use callbacks - -Task 4 - **Extra** -Create a form anywhere on your page. The form should have -- 4 input text fields, one for each property of your movie object -- a "save" button. -When the button is clicked -- The field values should be used to create a new movie object literal -- The new movie is then added to the list of movies and gets displayed on your page -TIP: Use the functions you created on tasks 1-3 - -Prefer to work on a codepen? https://codepen.io/makanti/pen/MWwMgmW?editors -================ -*/ -const movies = [ - { - title: "Color Out of Space", - director: "Richard Stanley", - type: "sci-fi", - haveWatched: true, - }, - { - title: "A Twelve-Year Night", - director: "Álvaro Brechner", - type: "horror", - haveWatched: false, - }, - { - title: "The Whistlers", - director: "Corneliu Porumboiu", - type: "comedy", - haveWatched: true, - }, - { - title: "The Invisible Man", - director: "Leigh Whannell", - type: "horror", - haveWatched: false, - }, -]; - -// create showMovies function - - -// create a new movie object for your favorite movie - - -// create addMovies function diff --git a/week-6/InClass/Callbacks/exercise-2/index.html b/week-6/InClass/Callbacks/exercise-2/index.html deleted file mode 100644 index bc9654c0b..000000000 --- a/week-6/InClass/Callbacks/exercise-2/index.html +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - CodeYourFuture - Callbacks - - - - - - - -

-
-

My movies

-
-

Number of movies:

-
-
- - - - \ No newline at end of file diff --git a/week-6/WEEK6-WORKED.md b/week-6/WEEK6-WORKED.md new file mode 100644 index 000000000..e69de29bb diff --git a/week-7/Homework/mandatory/1-debugging-practice/script.js b/week-7/Homework/mandatory/1-debugging-practice/script.js index dc14a775a..0ba49c50d 100644 --- a/week-7/Homework/mandatory/1-debugging-practice/script.js +++ b/week-7/Homework/mandatory/1-debugging-practice/script.js @@ -54,7 +54,7 @@ function render() { let table = document.getElementById("display"); let rowsNumber = table.rows.length; //delete old table - for (let n = rowsNumber - 1; n > 0; n-- { + for (let n = rowsNumber - 1; n > 0; n--) { table.deleteRow(n); } //insert updated row and cells diff --git a/week-7/InClass/1-Errors/exercise1.js b/week-7/InClass/1-Errors/exercise1.js new file mode 100644 index 000000000..dc7d6f489 --- /dev/null +++ b/week-7/InClass/1-Errors/exercise1.js @@ -0,0 +1,19 @@ +/* Remember to look at the error message, identify the +type of error, and see which line the error is on + +You don't need to fix this error, just explain WHY it +is happening */ + +let myName = "Reshma"; + +myName = myName.toUpperCase(); + +console.log(myName); + +let myAge = 44; + +myAge = myAge.toUpperCase(); + +console.log(myAge); + +//because myAge's value is a number, not string, we can add quotes around it, an it will work. diff --git a/week-7/InClass/1-Errors/exercise2.js b/week-7/InClass/1-Errors/exercise2.js new file mode 100644 index 000000000..97594728e --- /dev/null +++ b/week-7/InClass/1-Errors/exercise2.js @@ -0,0 +1,10 @@ +/* Remember to look at the error message, identify the +type of error, and see which line the error is on + +Then please fix the error! */ + +let myAge = 25; + +if (myAge > 18) { + console.log("Yes can vote"); +} diff --git a/week-7/InClass/1-Errors/exercise3.js b/week-7/InClass/1-Errors/exercise3.js new file mode 100644 index 000000000..836d932d9 --- /dev/null +++ b/week-7/InClass/1-Errors/exercise3.js @@ -0,0 +1,8 @@ +/* Remember to look at the error message, identify the +type of error, and see which line the error is on + +Then please fix the error! */ + +let greeting = "Hello"; + +console.log(greeting); diff --git a/week-7/InClass/1-Errors/exercise4.js b/week-7/InClass/1-Errors/exercise4.js new file mode 100644 index 000000000..363322322 --- /dev/null +++ b/week-7/InClass/1-Errors/exercise4.js @@ -0,0 +1,10 @@ +/* Remember to look at the error message, identify the +type of error, and see which line the error is on + +Then please fix the error! */ + +let ages = [4, 28, 55, 15]; + +let a = ages.length; + +console.log(a); diff --git a/week-7/InClass/1-Errors/exercise5.js b/week-7/InClass/1-Errors/exercise5.js new file mode 100644 index 000000000..0534ac5b4 --- /dev/null +++ b/week-7/InClass/1-Errors/exercise5.js @@ -0,0 +1,19 @@ +/* Remember to look at the error message, identify the +type of error, and see which line the error is on + +Then please fix the error! */ + +function calculateAgeInMonths(ages) { + let newArray = ages.map(multiplyBy12); + return newArray; +} + +function multiplyBy12(age) { + return age * 12; +} + +let peopleAges = [4, 28, 55, 15]; + +let agesInMonths = calculateAgeInMonths(peopleAges); + +console.log(agesInMonths); diff --git a/week-7/InClass/2-Debugging/exercise1.js b/week-7/InClass/2-Debugging/exercise1.js new file mode 100644 index 000000000..8ac46daaa --- /dev/null +++ b/week-7/InClass/2-Debugging/exercise1.js @@ -0,0 +1,16 @@ +/* +Run this code and see if there is a problem with the +output. + +Why is the bug happening? How do we fix it? +*/ + +function capitaliseName(name) { + return name.toUpperCase(); +} + +let myName = "santanu"; + +myName = capitaliseName(myName); + +console.log(myName); diff --git a/week-7/InClass/2-Debugging/exercise2.js b/week-7/InClass/2-Debugging/exercise2.js new file mode 100644 index 000000000..2168ce648 --- /dev/null +++ b/week-7/InClass/2-Debugging/exercise2.js @@ -0,0 +1,17 @@ +/* +Run this code and see if there is a problem with the +output. + +Why is the bug happening? How do we fix it? +*/ + +function greet(firstName, lastName) { + console.log("Hello " + firstName + " " + lastName); +} + +let myFirstName = "Safra"; + +let mySurname = "Catz"; + +greet(myFirstName, mySurname); +//we did not call function properly - we need to call it with both parameters diff --git a/week-7/InClass/2-Debugging/exercise3.js b/week-7/InClass/2-Debugging/exercise3.js new file mode 100644 index 000000000..5b96072d8 --- /dev/null +++ b/week-7/InClass/2-Debugging/exercise3.js @@ -0,0 +1,24 @@ +/* +We want our code to show the ages which are 17 or greater + +Run this code and see if there is a problem with the +output. + +Why is the bug happening? How do we fix it? +*/ + +function canDrive(a) { + if (a <= 17) { + return false; + } else { + return true; + } +} + +const ages = [22, 15, 29, 31, 7, 54, 13]; + +const legalDrivers = ages.filter(canDrive(ages)); + +console.log(legalDrivers); + +// We'd better fix this bug or our company will be sending out provisional driving licences to children! diff --git a/week-7/InClass/2-Debugging/exercise4.js b/week-7/InClass/2-Debugging/exercise4.js new file mode 100644 index 000000000..56fbeb5b9 --- /dev/null +++ b/week-7/InClass/2-Debugging/exercise4.js @@ -0,0 +1,22 @@ +/* +We were expecting the messyNames array to contain only Strings, +but it doesn't! + +First, can you understand why we get an error? What kind of error is it? + +Second - we asked the Business Analyst, and she told us if an element +is not a String, we should return the String "NO VALUE" - please +modify the code to do this +*/ + +function capitalise(customer) { + return customer.toUpperCase(); +} + +const messyNames = ["Sundar", "reshma", true, "Maria", "Shantanu", 5]; + +const customers = messyNames + .filter((el) => typeof el == "string") + .map(capitalise); + +console.log(customers); diff --git a/week-7/InClass/2-Debugging/exercise5.js b/week-7/InClass/2-Debugging/exercise5.js new file mode 100644 index 000000000..d74dd408f --- /dev/null +++ b/week-7/InClass/2-Debugging/exercise5.js @@ -0,0 +1,20 @@ +/* +We want to print the ages only of people who can vote + +But our code prints out all the ages! + +How can we change line 20 so we only print ages of people who can vote? +*/ + +function canVote(age) { + if (age >= 18) { + return true; + } else { + return false; + } +} +const ages = [17, 26, 4, 18, 7, 12, 31]; + +let canVoter = ages.filter(canVote); + +console.log(canVoter); diff --git a/week-7/InClass/2-Debugging/exercise6.js b/week-7/InClass/2-Debugging/exercise6.js new file mode 100644 index 000000000..0771e5d48 --- /dev/null +++ b/week-7/InClass/2-Debugging/exercise6.js @@ -0,0 +1,11 @@ +/* +Run this code and see if the result is what you expect + +What is the problem, and can you fix it? +*/ + +let myName = "Sundar"; + +if (myName == "Reshma") { + console.log("Hello"); +} diff --git a/week-7/InClass/3-Debugging-Library-Code/.gitattributes b/week-7/InClass/3-Debugging-Library-Code/.gitattributes new file mode 100644 index 000000000..dfe077042 --- /dev/null +++ b/week-7/InClass/3-Debugging-Library-Code/.gitattributes @@ -0,0 +1,2 @@ +# Auto detect text files and perform LF normalization +* text=auto diff --git a/week-7/InClass/3-Debugging-Library-Code/README.md b/week-7/InClass/3-Debugging-Library-Code/README.md new file mode 100644 index 000000000..f057f51ac --- /dev/null +++ b/week-7/InClass/3-Debugging-Library-Code/README.md @@ -0,0 +1,16 @@ +# Debugging My Book Library + +My website should be able to: + +- View a list of books that I've read +- Add books to a list of books that I've read + - Including title, author, number of pages and if I've read it + - If any of the information is missing it shouldn't add the book and should show an alert +- Remove books from my list + +## Task + +This purposefully broken website should use the tools we talked about in the lesson. + +You can find a working version of this here: +https://arodrigues92.github.io/library/ diff --git a/week-7/InClass/3-Debugging-Library-Code/index.html b/week-7/InClass/3-Debugging-Library-Code/index.html new file mode 100644 index 000000000..4255bdd17 --- /dev/null +++ b/week-7/InClass/3-Debugging-Library-Code/index.html @@ -0,0 +1,82 @@ + + + + + + Odin's Library + + + + + + + + +
+

Odin's Library

+
+
+ +
+
+
+
+
+ + +
+
+ + +
+
+
+ + +
+
+ + +
+
+
+ +
+
+
+
+
+
+ + + + + + + + + + +
TitleAuthorPagesRead
+
+
+ +
+
+ + + diff --git a/week-7/InClass/3-Debugging-Library-Code/main.js b/week-7/InClass/3-Debugging-Library-Code/main.js new file mode 100644 index 000000000..80cd3e708 --- /dev/null +++ b/week-7/InClass/3-Debugging-Library-Code/main.js @@ -0,0 +1,169 @@ +const addButtons = document.querySelectorAll(".add-button"); +const formContainer = document.getElementById("form-container"); +const tableBody = document.getElementById("table-body"); +const submit = document.getElementById("submit"); + +let bookNumber = 0; +let myLibrary = []; + +const book1 = { + title: "Crime and punishment", + author: "Fyodor Dostoyevksy", + page: 671, + read: "Yes", +}; +const book2 = { + title: "A brief history of time", + author: "Stephen Hawking", + page: 212, + read: "No", +}; + +myLibrary.push(book1); +myLibrary.push(book2); + +render(); + +addButtons.forEach((button) => { + button.addEventListener("click", () => { + formContainer.style.display = "block"; + }); +}); + +function addDeleteButtons() { + let deleteButtons = document.querySelectorAll(".delete"); + deleteButtons.forEach((button) => { + if (button.getAttribute("data-book") == bookNumber) { + //Only add eventListeners to new books + button.addEventListener("click", () => { + deleteBook(button.getAttribute("data-book")); + }); + } + }); +} + +function addReadButtons() { + let readButtons = document.querySelectorAll(".change-read"); + + readButtons.forEach((button) => { + if (button.getAttribute("data-book") == bookNumber) { + button.addEventListener("click", () => { + changeReadStatus(button.getAttribute("data-book"), button); + }); + } + }); +} + +function deleteBook(number) { + let toDelete = document.querySelector(`tr[data-book="${number}"]`); + toDelete.remove(); +} + +function changeReadStatus(number, button) { + if (myLibrary[number]["read"] === "Yes") { + myLibrary[number]["read"] = "No"; + button.innerText = "No"; + button.classList.remove("button-green"); + button.classList.add("button-red"); + } else { + myLibrary[number]["read"] = "Yes"; + button.innerText = "Yes"; + button.classList.remove("button-red"); + button.classList.add("button-green"); + } +} + +function addBookToLibrary(title, author, pages, read) { + let book = { title: title, author: author, page: pages, read: read }; + myLibrary.push(book); +} + +function render() { + for (let i = 0; i < myLibrary.length; i++) { + if (i === bookNumber) { + let row = document.createElement("tr"); + + if (bookNumber % 2 !== 0) { + //Adds color to every other row + row.classList.add("color-row"); + } + + row.setAttribute("data-book", bookNumber); + + let titleCell = document.createElement("td"); + titleCell.append(myLibrary[i].title); + row.append(titleCell); + + let authorCell = document.createElement("td"); + authorCell.append(myLibrary[i].author); + row.append(authorCell); + + let pageCell = document.createElement("td"); + pageCell.append(myLibrary[i].page); + row.append(pageCell); + + let readCell = document.createElement("td"); + let button = document.createElement("button"); + button.innerText = myLibrary[i].read; + + if (myLibrary[i].read === "Yes") { + button.classList.add("button-green"); + } else { + button.classList.add("button-red"); + } + + button.classList.add("change-read"); + button.setAttribute("type", "button"); + button.setAttribute("data-book", bookNumber); + readCell.append(button); + row.append(readCell); + + let deleteCell = document.createElement("td"); + let deleteB = document.createElement("button"); + let icon = document.createElement("ion-icon"); + icon.setAttribute("name", "trash-outline"); + deleteB.classList.add("delete"); + deleteB.setAttribute("type", "button"); + deleteB.setAttribute("data-book", bookNumber); + + deleteB.append(icon); + deleteCell.append(deleteB); + row.append(deleteCell); + + tableBody.insertBefore(row, tableBody.firstChild); + + addDeleteButtons(); + addReadButtons(); + + bookNumber++; + } + } +} + +submit.addEventListener("click", (e) => { + e.preventDefault(); + + let form = document.querySelector("form"); + let bookArgs = []; + + for (let i = 0; i < form.elements.length; i++) { + let element = form.elements[i]; + if (element.id === "read") { + if (element.checked === true) { + bookArgs.push("Yes"); + } else { + bookArgs.push("No"); + } + element.checked = false; + } else { + bookArgs.push(element.value); + if (element.id !== "submit") { + element.value = ""; + } + } + } + + formContainer.style.display = "none"; + addBookToLibrary(bookArgs[1], bookArgs[0], bookArgs[2], bookArgs[3]); + render(); +}); diff --git a/week-7/InClass/3-Debugging-Library-Code/styles/main.css b/week-7/InClass/3-Debugging-Library-Code/styles/main.css new file mode 100644 index 000000000..9ad03632d --- /dev/null +++ b/week-7/InClass/3-Debugging-Library-Code/styles/main.css @@ -0,0 +1,308 @@ +body { + background-color: #fffaed; + font-size: 10px; +} + +#h1-container { + display: flex; + justify-content: center; + margin-top: 5vh; +} + +h1 { + font-size: 5em; +} + +#mobile-button-container { + display: flex; + justify-content: center; + margin: 3vh 0; +} + +.add-button { + position: relative; + width: 100px; + height: 30px; + margin-left: 30px; + margin-top: 15px; + color: #ffffff; + font-weight: bold; + background-color: green; + text-align: center; + border: none; + outline: none; +} + +.add-button:hover { + cursor: pointer; + background-color: #007400; + transform: scale(1.2); +} + +#add-button-mobile { + margin: 0; +} + +#add-button-mobile:before { + content: ""; + position: absolute; + right: 0px; + top: 100%; + width: 0px; + height: 0px; + border-right: 50px solid transparent; + border-left: 50px solid transparent; + border-top: 15px solid green; +} + +#add-button-mobile:hover:before { + border-top-color: #007400; +} + +#form-container { + display: none; +} + +#inputs-container { + display: flex; + flex-direction: column; + align-items: center; +} + +.input { + margin-top: 1vh; + display: flex; + align-items: center; + justify-content: space-between; + width: 75vw; +} + +#input-group { + display: flex; + justify-content: center; + width: 75vw; +} + +.small-input { + display: flex; + align-items: center; + justify-content: space-between; + width: 20vw; + margin: 2vw 5vw 0 0; +} + +#checkbox-container { + width: 12vw; +} + +.text-input { + width: 60vw; +} + +#input-group { + display: flex; + width: 60vw; +} + +#pages { + width: 10vw; +} + +#read { + margin: 0 0 1px 0; +} + +#submit-container { + margin-top: 1vh; +} + +#submit-container input { + background-color: green; + color: white; + border: none; + outline: none; + font-weight: bold; + padding: 5px 10px; +} + +#main-container { + display: flex; + justify-content: center; + margin-top: 5vh; +} + +table { + border-collapse: separate; + border-spacing: 0 5px; +} + +.color-row { + background-color: #ece0c3; +} + +.color-row td { + padding: 7px 0; +} + +th { + font-size: 1.6em; + font-weight: bold; + padding: 0 1vw 0 1vw; +} + +td { + font-size: 1em; + text-align: center; + vertical-align: middle; + padding: 2px 1vw 2px 1vw; +} + +.change-read { + color: white; + font-weight: bold; + font-size: 1em; + width: 35px; + padding: 4px 0; +} + +.button-green { + background-color: green; +} + +.button-red { + background-color: #d20000; +} + +.button-green:hover { + background-color: #007400; +} + +.button-red:hover { + background-color: #c70000; +} + +td button { + border: none; + outline: none; + background: none; + cursor: pointer; +} + +#desktop-button-container { + display: flex; +} + +#add-button-desktop:before { + content: ""; + position: absolute; + right: 100%; + top: 0px; + width: 0px; + height: 0px; + border-top: 15px solid transparent; + border-right: 15px solid green; + border-bottom: 15px solid transparent; +} + +#add-button-desktop:hover:before { + border-right-color: #007400; +} + +#add-button-desktop { + display: none; +} + +@media only screen and (min-width: 768px) { + body { + font-size: 14px; + } + + #mobile-button-container { + display: none; + } + + #form-container { + margin-top: 5vh; + } + + #inputs-container { + flex-direction: row; + justify-content: center; + } + + .input { + flex-direction: column; + margin: 0 20px; + width: 200px; + } + + .text-input { + width: 200px; + } + + .small-input { + flex-direction: column; + width: 50px; + margin: 0 20px; + } + + #input-group { + width: 100px; + margin: 0 20px; + } + + #pages { + width: 50px; + } + + #checkbox-container { + width: 50px; + } + + #submit-container { + align-self: flex-end; + margin: 0 0 0 20px; + } + + #submit-container input { + width: 80px; + height: 30px; + } + + #submit-container input:hover { + cursor: pointer; + } + + #add-button-desktop { + display: inline-block; + } + + #table-container { + margin-left: 130px; /* centers the table by giving it a left margin of the size+margin of the add button */ + } + + th { + font-size: 2em; + } + + td { + font-size: 1.4em; + } + + td .delete:hover { + transform: scale(1.5); + } + + .change-read { + width: 50px; + } + + .button-green:hover, + .button-red:hover { + transform: scale(1.3); + } + + ion-icon { + font-size: 1.4em; + } +} diff --git a/week-7/InClass/3-Debugging-Library-Code/styles/reset.css b/week-7/InClass/3-Debugging-Library-Code/styles/reset.css new file mode 100644 index 000000000..45a05ecf8 --- /dev/null +++ b/week-7/InClass/3-Debugging-Library-Code/styles/reset.css @@ -0,0 +1,129 @@ +/* http://meyerweb.com/eric/tools/css/reset/ + v2.0 | 20110126 + License: none (public domain) +*/ + +html, +body, +div, +span, +applet, +object, +iframe, +h1, +h2, +h3, +h4, +h5, +h6, +p, +blockquote, +pre, +a, +abbr, +acronym, +address, +big, +cite, +code, +del, +dfn, +em, +img, +ins, +kbd, +q, +s, +samp, +small, +strike, +strong, +sub, +sup, +tt, +var, +b, +u, +i, +center, +dl, +dt, +dd, +ol, +ul, +li, +fieldset, +form, +label, +legend, +table, +caption, +tbody, +tfoot, +thead, +tr, +th, +td, +article, +aside, +canvas, +details, +embed, +figure, +figcaption, +footer, +header, +hgroup, +menu, +nav, +output, +ruby, +section, +summary, +time, +mark, +audio, +video { + margin: 0; + padding: 0; + border: 0; + font-size: 100%; + font: inherit; + vertical-align: baseline; +} +/* HTML5 display-role reset for older browsers */ +article, +aside, +details, +figcaption, +figure, +footer, +header, +hgroup, +menu, +nav, +section { + display: block; +} +body { + line-height: 1; +} +ol, +ul { + list-style: none; +} +blockquote, +q { + quotes: none; +} +blockquote:before, +blockquote:after, +q:before, +q:after { + content: ""; + content: none; +} +table { + border-collapse: collapse; + border-spacing: 0; +} diff --git a/week-8/Homework/mandatory/2-fetch-exercise/exercise.js b/week-8/Homework/mandatory/2-fetch-exercise/exercise.js index fb3a39c2a..5acc7ff72 100644 --- a/week-8/Homework/mandatory/2-fetch-exercise/exercise.js +++ b/week-8/Homework/mandatory/2-fetch-exercise/exercise.js @@ -16,11 +16,14 @@ Expected result Open index.html in your browser. Every time you refresh the page, a different greeting should be displayed in the box. */ - -fetch('*** Write the API address here ***') - .then(function(response) { - return response.text(); +function setup() { + fetch("https://codeyourfuture.herokuapp.com/api/greetings") + .then(function (response) { + return response.text(); }) - .then(function(greeting) { - // Write the code to display the greeting text here - }); \ No newline at end of file + .then(function (greeting) { + // Write the code to display the greeting text here + document.querySelector("#greeting-text").textContent = greeting; + }); +} +window.onload = setup; diff --git a/week-8/Homework/mandatory/3-dog-photo-gallery/index.html b/week-8/Homework/mandatory/3-dog-photo-gallery/index.html new file mode 100644 index 000000000..c4431f5d6 --- /dev/null +++ b/week-8/Homework/mandatory/3-dog-photo-gallery/index.html @@ -0,0 +1,45 @@ + + + + + + Dog photo gallery + + + + + + + + + + + + diff --git a/week-8/Homework/mandatory/4-programmer-humour/index.html b/week-8/Homework/mandatory/4-programmer-humour/index.html new file mode 100644 index 000000000..cede82e83 --- /dev/null +++ b/week-8/Homework/mandatory/4-programmer-humour/index.html @@ -0,0 +1,15 @@ + + + + + + Dog photo gallery + + + + + + Some photo + + + diff --git a/week-8/Homework/mandatory/4-programmer-humour/script.js b/week-8/Homework/mandatory/4-programmer-humour/script.js new file mode 100644 index 000000000..a1bc0fdd7 --- /dev/null +++ b/week-8/Homework/mandatory/4-programmer-humour/script.js @@ -0,0 +1,10 @@ +fetch("https://xkcd.now.sh/?comic=latest") + .then(function (result) { + return result.json(); + }) + + .then(function (humor) { + console.log(humor); + document.querySelector("#image").src = humor.img; + }) + .catch((error) => console.log(error)); diff --git a/week-8/Homework/mandatory/4-programmer-humour/style.css b/week-8/Homework/mandatory/4-programmer-humour/style.css new file mode 100644 index 000000000..e69de29bb diff --git a/week-8/InClass/1-Calling-Functions/exercise1.js b/week-8/InClass/1-Calling-Functions/exercise1.js new file mode 100644 index 000000000..a3e5e948f --- /dev/null +++ b/week-8/InClass/1-Calling-Functions/exercise1.js @@ -0,0 +1,23 @@ +/* +ONLY CHANGE LINE 21 to answer this question + +This code has a bug - if we run it we see the result "Hello undefined" + +Why are we getting this result? + +Please fix this code so we get the result "Hello Marissa" + +ONLY CHANGE LINE 21 +*/ + +function greet(name) { + name = "Hello " + name; + return name; +} + +let myName = "Marissa"; + +// ONLY CHANGE CODE ON LINE 21 +let greeting = greet(myName); + +console.log(greeting); diff --git a/week-8/InClass/1-Calling-Functions/exercise2.js b/week-8/InClass/1-Calling-Functions/exercise2.js new file mode 100644 index 000000000..92ebcbbe7 --- /dev/null +++ b/week-8/InClass/1-Calling-Functions/exercise2.js @@ -0,0 +1,25 @@ +/* +ONLY CHANGE LINE 23 to answer this question + +This code has a bug - if we run it we see the result "NaN" +This means "Not a Number", we get this when we try to multiply (or divide, add, subtract etc) +a variable which is not of type = number + +Why are we getting this result? + +Please fix this code so we get the result 10 + +ONLY CHANGE LINE 23 +*/ + +function doubleNumber(num) { + num = num * 2; + return num; +} + +let a = 5; + +// ONLY CHANGE CODE ON LINE 23 +let b = doubleNumber(a); + +console.log(b); diff --git a/week-8/InClass/1-Calling-Functions/exercise3.js b/week-8/InClass/1-Calling-Functions/exercise3.js new file mode 100644 index 000000000..0a666535e --- /dev/null +++ b/week-8/InClass/1-Calling-Functions/exercise3.js @@ -0,0 +1,25 @@ +/* +ONLY CHANGE LINE 23 to answer this question + +This code has a bug - if we run it we see the result "John undefined" + +Why are we getting this result? + +Please fix this code so we get the result "John Legere" + +ONLY CHANGE LINE 23 +*/ + +function fullName(firstName, surname) { + let fullName = firstName + " " + surname; + return fullName; +} + +let customerFirstName = "John"; + +let customerSurname = "Legere"; + +// ONLY CHANGE CODE ON LINE 23 +let customerFullName = fullName(customerFirstName, customerSurname); + +console.log(customerFullName); diff --git a/week-8/InClass/1-Calling-Functions/exercise4.js b/week-8/InClass/1-Calling-Functions/exercise4.js new file mode 100644 index 000000000..18ad42362 --- /dev/null +++ b/week-8/InClass/1-Calling-Functions/exercise4.js @@ -0,0 +1,21 @@ +/* +ONLY CHANGE LINE 19 to answer this question + +We would like to see the result "10" but we are getting result "5" + +Please change this code so we get the result 10 + +ONLY CHANGE LINE 19 +*/ + +function doubleNumber(num) { + num = num * 2; + return num; +} + +let a = 5; + +// ONLY CHANGE CODE ON LINE 19 +a = doubleNumber(a); + +console.log(a); diff --git a/week-8/InClass/1-Calling-Functions/exercise5.js b/week-8/InClass/1-Calling-Functions/exercise5.js new file mode 100644 index 000000000..167fc2c4f --- /dev/null +++ b/week-8/InClass/1-Calling-Functions/exercise5.js @@ -0,0 +1,25 @@ +/* +ONLY CHANGE LINE 23 to answer this question + +This code has a bug - run it and see what the result is + +Why are we getting this result? + +Please fix this code so we get the result "38" + +ONLY CHANGE LINE 23 +*/ + +function calculateAge(yearOfBirth, currentYear) { + let age = currentYear - yearOfBirth; + return age; +} + +let yearIWasBorn = 1982; + +let thisYear = 2020; + +// ONLY CHANGE CODE ON LINE 23 +let myAge = calculateAge(yearIWasBorn, thisYear); + +console.log(myAge); diff --git a/week-8/InClass/2-Functions/exercise1.js b/week-8/InClass/2-Functions/exercise1.js new file mode 100644 index 000000000..5cf995e3e --- /dev/null +++ b/week-8/InClass/2-Functions/exercise1.js @@ -0,0 +1,19 @@ +/* +What is the value we expect to see in the console? + +Why do we see "undefined"? + +ONLY CHANGE the code of calculateAgeInMonths function - +please fix this bug so we see the result is "360" +*/ + +function calculateAgeInMonths(ageInYears) { + let ageInMonths = ageInYears * 12; + return ageInMonths; +} + +let myAge = 30; + +let myAgeInMonths = calculateAgeInMonths(myAge); + +console.log(myAgeInMonths); diff --git a/week-8/InClass/2-Functions/exercise2.js b/week-8/InClass/2-Functions/exercise2.js new file mode 100644 index 000000000..b13409d8e --- /dev/null +++ b/week-8/InClass/2-Functions/exercise2.js @@ -0,0 +1,23 @@ +/* +What is the value we expect to see in the console? + +What is the TYPE of error, and what LINE NUMBER does it happen at? What is the ERROR MESSAGE? + +Why are we getting this error? + +ONLY CHANGE the code of calculateArea function - +please fix this bug so we see the result is "30" +*/ + +function calculateArea(x, y) { + let areaValue = x * y; + return areaValue; +} + +let width = 10; + +let height = 3; + +let area = calculateArea(width, height); + +console.log(area); diff --git a/week-8/InClass/2-Functions/exercise3.js b/week-8/InClass/2-Functions/exercise3.js new file mode 100644 index 000000000..067433c8f --- /dev/null +++ b/week-8/InClass/2-Functions/exercise3.js @@ -0,0 +1,18 @@ +/* +In this exercise, you have to write the code for the function! + +ONLY change the code inside the calculateArea function +*/ + +function calculateArea(x, y) { + // write your code here + return x * y; +} + +let width = 5; + +let height = 10; + +let area = calculateArea(width, height); + +console.log(area); diff --git a/week-8/InClass/2-Functions/exercise4.js b/week-8/InClass/2-Functions/exercise4.js new file mode 100644 index 000000000..1ec5743be --- /dev/null +++ b/week-8/InClass/2-Functions/exercise4.js @@ -0,0 +1,22 @@ +/* +In this exercise, you have to make the code work +by writing a function! + +Look at where the function is being called (line 20) +What is the name of the function we need? +How many input parameters do we need? +What is the result we need to return? + +To complete this exercise you ONLY need to +write the function +*/ +function calculateMonthsInYear(time) { + // write your function here + return time * 12; +} +// Don't change any of the code below +let years = 5; + +let months = calculateMonthsInYear(years); + +console.log(months); diff --git a/week-8/InClass/2-Functions/exercise5-example1.js b/week-8/InClass/2-Functions/exercise5-example1.js new file mode 100644 index 000000000..6767de7ca --- /dev/null +++ b/week-8/InClass/2-Functions/exercise5-example1.js @@ -0,0 +1,33 @@ +/* +READ ONLY - this is an example to help you with the next question. + +We have written code which does the SAME calculation 3 times! +Remember the DRY principle - Don't Repeat Yourself. +This is a good time to use a function. + +We can write a function to do the calculation, and +change our code so it CALLS the function 3 times + +When we change our code like this we say we are REFACTORING + +Look at exercise5-example2.js to see the refactored code. +*/ + +let width1 = 10; +let height1 = 2; +let length1 = 3; +let volume1 = width1 * height1 * length1; + +let width2 = 4; +let height2 = 6; +let length2 = 2; +let volume2 = width2 * height2 * length2; + +let width3 = 8; +let height3 = 3; +let length3 = 5; +let volume3 = width3 * height3 * length3; + +console.log(volume1); +console.log(volume2); +console.log(volume3); diff --git a/week-8/InClass/2-Functions/exercise5-example2.js b/week-8/InClass/2-Functions/exercise5-example2.js new file mode 100644 index 000000000..fa859ba14 --- /dev/null +++ b/week-8/InClass/2-Functions/exercise5-example2.js @@ -0,0 +1,35 @@ +/* +READ ONLY - this is an example to help you with the next question. + +Now we have refactored the code so our calculation is only written once. +If we ever have to change it, we only need to change it in one place. + +Remember after refactoring we should still get the SAME result! +Check the output of this code with the last one to check the results are the same. + +Now do exercise5-question.js. +*/ + +function calculateVolume(x, y, z){ + let volume = x * y * z; + return volume; +} + +let width1 = 10; +let height1 = 2; +let length1 = 3; +let volume1 = calculateVolume(width1, height1, length1); + +let width2 = 4; +let height2 = 6; +let length2 = 2; +let volume2 = calculateVolume(width2, height2, length2); + +let width3 = 8; +let height3 = 3; +let length3 = 5; +let volume3 = calculateVolume(width3, height3, length3); + +console.log(volume1); +console.log(volume2); +console.log(volume3); diff --git a/week-8/InClass/2-Functions/exercise5-question.js b/week-8/InClass/2-Functions/exercise5-question.js new file mode 100644 index 000000000..9843e6eef --- /dev/null +++ b/week-8/InClass/2-Functions/exercise5-question.js @@ -0,0 +1,32 @@ +/* +We have written code below that does the same thing 3 times. + +We should REFACTOR this code. + +We should write a function, and call the function 3 times. + +The results should stay THE SAME +*/ + +let firstName1 = "Katrina"; +let surname1 = "Lake"; +// Change the line below to call your function! +let greeting1 = greeting(firstName1, surname1); + +let firstName2 = "Eric"; +let surname2 = "Yuan"; +// Change the line below to call your function! +let greeting2 = greeting(firstName2, surname2); + +let firstName3 = "Jeff"; +let surname3 = "Bezos"; +// Change the line below to call your function! +let greeting3 = greeting(firstName3, surname3); + +console.log(greeting1); +console.log(greeting2); +console.log(greeting3); + +function greeting(name, surname) { + return "Hello " + name + " " + surname; +} diff --git a/week-8/InClass/3-fetch/data.json b/week-8/InClass/3-fetch/data.json new file mode 100644 index 000000000..e756f5407 --- /dev/null +++ b/week-8/InClass/3-fetch/data.json @@ -0,0 +1,10 @@ +[ + { + "name": "Alex", + "age": 21 + }, + { + "name": "Anna", + "age": 52 + } +] \ No newline at end of file diff --git a/week-8/InClass/3-fetch/exercise.js b/week-8/InClass/3-fetch/exercise.js new file mode 100644 index 000000000..d5373dfc4 --- /dev/null +++ b/week-8/InClass/3-fetch/exercise.js @@ -0,0 +1,15 @@ +/* + 1. Fetch the "people" array from the "data.json" file + 2. And console.log() the name of the first person. + + Remember to open "index.html" using Live Preview, and test that you get the correct results in the console! + (you should see "Alex") + */ +fetch("data.json") + // Get the response and extract the JSON + .then(function (response) { + return response.json(); + }) + .then(function (person) { + console.log(person[0].name); + }); diff --git a/week-8/InClass/3-fetch/index.html b/week-8/InClass/3-fetch/index.html new file mode 100644 index 000000000..02e424a19 --- /dev/null +++ b/week-8/InClass/3-fetch/index.html @@ -0,0 +1,11 @@ + + + + + Fetch + + + + Open the console to see your results! + + diff --git a/week-8/InClass/4-APIs/exercise.js b/week-8/InClass/4-APIs/exercise.js new file mode 100644 index 000000000..fda766ecb --- /dev/null +++ b/week-8/InClass/4-APIs/exercise.js @@ -0,0 +1,26 @@ +/* + 1. Fetch the results from this API: https://cat-fact.herokuapp.com/facts + And console.log the first cat fact + + 2. Fetch the results from this API: https://restcountries.eu/rest/v2/name/Great%20Britain?fullText=true + And console.log the population of the UK + + Remember to open "index.html" using Live Preview, and test that you get the correct results in the console! + */ +fetch("https://cat-fact.herokuapp.com/facts") + .then(function (result) { + return result.json(); + }) + + .then(function (cat_info) { + console.log(cat_info.all[0].text); + }); + +fetch("https://restcountries.eu/rest/v2/name/Great%20Britain?fullText=true") + .then(function (result) { + return result.json(); + }) + + .then(function (uk_info) { + console.log(uk_info[0].population); + }); diff --git a/week-8/InClass/4-APIs/index.html b/week-8/InClass/4-APIs/index.html new file mode 100644 index 000000000..02e424a19 --- /dev/null +++ b/week-8/InClass/4-APIs/index.html @@ -0,0 +1,11 @@ + + + + + Fetch + + + + Open the console to see your results! + +