From 3658800f09529124f12e23b0794aae942ebdc827 Mon Sep 17 00:00:00 2001 From: NihalAli2 <62475392+NihalAli2@users.noreply.github.com> Date: Sat, 20 Jun 2020 02:54:03 +0100 Subject: [PATCH 01/22] week1 --- .vscode/launch.json | 18 ++++++++++++ week-1/1-exercises/B-hello-world/exercise.js | 1 + week-1/1-exercises/C-variables/exercise.js | 4 ++- week-1/1-exercises/D-strings/exercise.js | 4 ++- .../E-strings-concatenation/exercise.js | 7 ++++- .../1-exercises/F-strings-methods/exercise.js | 5 +++- .../F-strings-methods/exercise2.js | 5 ++-- week-1/1-exercises/G-numbers/exercise.js | 3 ++ week-1/1-exercises/I-floats/exercise.js | 4 ++- .../K-functions-parameters/exercise.js | 4 +-- .../K-functions-parameters/exercise2.js | 4 ++- .../K-functions-parameters/exercise3.js | 6 ++-- week-1/2-mandatory/1-syntax-errors.js | 6 ++-- week-1/2-mandatory/2-logic-error.js | 28 ++++++++++++------- week-1/2-mandatory/3-function-output.js | 16 +++++++---- week-1/2-mandatory/4-tax.js | 13 ++++++--- 16 files changed, 94 insertions(+), 34 deletions(-) create mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..a070426 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,18 @@ +{ + // 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": "pwa-node", + "request": "launch", + "name": "Launch Program", + "skipFiles": [ + "/**" + ], + "program": "${workspaceFolder}\\week-1\\2-mandatory\\3-function-output.js" + } + ] +} \ No newline at end of file diff --git a/week-1/1-exercises/B-hello-world/exercise.js b/week-1/1-exercises/B-hello-world/exercise.js index b179ee9..af90bfd 100644 --- a/week-1/1-exercises/B-hello-world/exercise.js +++ b/week-1/1-exercises/B-hello-world/exercise.js @@ -1 +1,2 @@ +var name = "Hello world!"; console.log("Hello world"); diff --git a/week-1/1-exercises/C-variables/exercise.js b/week-1/1-exercises/C-variables/exercise.js index a6bbb97..980ecbd 100644 --- a/week-1/1-exercises/C-variables/exercise.js +++ b/week-1/1-exercises/C-variables/exercise.js @@ -1,3 +1,5 @@ // Start by creating a variable `greeting` - +var greeting ="Hello World"; +console.log(greeting); +console.log(greeting); console.log(greeting); diff --git a/week-1/1-exercises/D-strings/exercise.js b/week-1/1-exercises/D-strings/exercise.js index 2cffa6a..b9433fe 100644 --- a/week-1/1-exercises/D-strings/exercise.js +++ b/week-1/1-exercises/D-strings/exercise.js @@ -1,3 +1,5 @@ // Start by creating a variable `message` +var message = "This is a string"; +var messageType = typeof message; -console.log(message); +console.log(messageType); diff --git a/week-1/1-exercises/E-strings-concatenation/exercise.js b/week-1/1-exercises/E-strings-concatenation/exercise.js index 2cffa6a..e4483c3 100644 --- a/week-1/1-exercises/E-strings-concatenation/exercise.js +++ b/week-1/1-exercises/E-strings-concatenation/exercise.js @@ -1,3 +1,8 @@ // Start by creating a variable `message` +var greetingStart = "Hello, my name is "; +var name = "Nihal"; + +var greeting = greetingStart + name; + +console.log(greeting); -console.log(message); diff --git a/week-1/1-exercises/F-strings-methods/exercise.js b/week-1/1-exercises/F-strings-methods/exercise.js index 2cffa6a..5011ff9 100644 --- a/week-1/1-exercises/F-strings-methods/exercise.js +++ b/week-1/1-exercises/F-strings-methods/exercise.js @@ -1,3 +1,6 @@ // Start by creating a variable `message` +var name = "Daniel"; +var nameLength = name.length; + +console.log(nameLength); -console.log(message); diff --git a/week-1/1-exercises/F-strings-methods/exercise2.js b/week-1/1-exercises/F-strings-methods/exercise2.js index b4b4694..87c3ae2 100644 --- a/week-1/1-exercises/F-strings-methods/exercise2.js +++ b/week-1/1-exercises/F-strings-methods/exercise2.js @@ -1,3 +1,4 @@ -const name = " Daniel "; +var name = "Daniel"; +var nameLowerCase = name.toLowerCase(); -console.log(message); +console.log(nameLowerCase); \ No newline at end of file diff --git a/week-1/1-exercises/G-numbers/exercise.js b/week-1/1-exercises/G-numbers/exercise.js index 49e7bc0..c69e7c9 100644 --- a/week-1/1-exercises/G-numbers/exercise.js +++ b/week-1/1-exercises/G-numbers/exercise.js @@ -1 +1,4 @@ // Start by creating a variables `numberOfStudents` and `numberOfMentors` +var numberOfStudent = 15; +var numberOfMentors = 8; +var sum = numberOfStudent + numberOfMentors; \ No newline at end of file diff --git a/week-1/1-exercises/I-floats/exercise.js b/week-1/1-exercises/I-floats/exercise.js index a5bbcd8..9aaae41 100644 --- a/week-1/1-exercises/I-floats/exercise.js +++ b/week-1/1-exercises/I-floats/exercise.js @@ -1,2 +1,4 @@ var numberOfStudents = 15; -var numberOfMentors = 8; +var numberOfStudents = 8; +var total = numberOfStudents + numberOfStudents; +var percentagOfStudents = Math.round((numberOfStudents/total)*100); \ No newline at end of file diff --git a/week-1/1-exercises/K-functions-parameters/exercise.js b/week-1/1-exercises/K-functions-parameters/exercise.js index 8d5db5e..ccc3641 100644 --- a/week-1/1-exercises/K-functions-parameters/exercise.js +++ b/week-1/1-exercises/K-functions-parameters/exercise.js @@ -1,6 +1,6 @@ // Complete the function so that it takes input parameters -function multiply() { - // Calculate the result of the function and return it +function multiply(a, b) { + return a*b; } // Assign the result of calling the function the variable `result` diff --git a/week-1/1-exercises/K-functions-parameters/exercise2.js b/week-1/1-exercises/K-functions-parameters/exercise2.js index db7a890..8b6ae2a 100644 --- a/week-1/1-exercises/K-functions-parameters/exercise2.js +++ b/week-1/1-exercises/K-functions-parameters/exercise2.js @@ -1,4 +1,6 @@ -// Declare your function first +function divide(a, b) { + return a/b; +} var result = divide(3, 4); diff --git a/week-1/1-exercises/K-functions-parameters/exercise3.js b/week-1/1-exercises/K-functions-parameters/exercise3.js index 537e9f4..0a724ea 100644 --- a/week-1/1-exercises/K-functions-parameters/exercise3.js +++ b/week-1/1-exercises/K-functions-parameters/exercise3.js @@ -1,5 +1,7 @@ -// Write your function here +function createGreeting(num1, num2) { + return num1 + num2; +} -var greeting = createGreeting("Daniel"); +var greeting = createGreeting("Hello, my name is ", "Nihal."); console.log(greeting); diff --git a/week-1/2-mandatory/1-syntax-errors.js b/week-1/2-mandatory/1-syntax-errors.js index 6910f28..415720b 100644 --- a/week-1/2-mandatory/1-syntax-errors.js +++ b/week-1/2-mandatory/1-syntax-errors.js @@ -2,15 +2,15 @@ // There are syntax errors in this code - can you fix it to pass the tests? -function addNumbers(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"; +return 'Hello, my name is ' + name + 'and I am '+ age + 'years old'; function getAddition(a, b) { - total = a ++ b + total = a + b // Use string interpolation here return "The total is %{total}" diff --git a/week-1/2-mandatory/2-logic-error.js b/week-1/2-mandatory/2-logic-error.js index 1e0a9d4..43da8cf 100644 --- a/week-1/2-mandatory/2-logic-error.js +++ b/week-1/2-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 ===== @@ -22,14 +21,23 @@ To run these tests type `node 2-logic-error` into your terminal 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 + ); \ No newline at end of file diff --git a/week-1/2-mandatory/3-function-output.js b/week-1/2-mandatory/3-function-output.js index bbb88a2..3956bdf 100644 --- a/week-1/2-mandatory/3-function-output.js +++ b/week-1/2-mandatory/3-function-output.js @@ -1,9 +1,14 @@ // Add comments to explain what this function does. You're meant to use Google! + +//returen random number between 0 ans 9.99 function getNumber() { return Math.random() * 10; } // Add comments to explain what this function does. You're meant to use Google! + +// this function takes one array and merges into another +// if first parameter w1 is a string, then it will do just a string concatenation function s(w1, w2) { return w1.concat(w2); } @@ -11,6 +16,7 @@ function s(w1, 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 + return `${firstWord} ${secondWord} ${thirdWord}`; } /* ======= TESTS - DO NOT MODIFY ===== @@ -22,9 +28,9 @@ To run these tests type `node 3-function-output` into your terminal function test(test_name, expr) { let status; if (expr) { - status = "PASSED"; + status = 'PASSED'; } else { - status = "FAILED"; + status = 'FAILED'; } console.log(`${test_name}: ${status}`); @@ -32,13 +38,13 @@ function test(test_name, expr) { test( "concatenate function - case 1 works", - concatenate("code", "your", "future") === "code your future" + concatenate('code', 'your', 'future') === 'code your future' ); test( "concatenate function - case 2 works", - concatenate("I", "like", "pizza") === "I like pizza" + concatenate('I', 'like', 'pizza') === 'I like pizza' ); test( "concatenate function - case 3 works", - concatenate("I", "am", 13) === "I am 13" + concatenate('I', 'am', 13) === 'I am 13' ); diff --git a/week-1/2-mandatory/4-tax.js b/week-1/2-mandatory/4-tax.js index 6b84208..cbd343e 100644 --- a/week-1/2-mandatory/4-tax.js +++ b/week-1/2-mandatory/4-tax.js @@ -5,7 +5,10 @@ Sales tax is 20% of the price of the product */ -function calculateSalesTax() {} +function calculateSalesTax(price) { + const tax = price * 0.2; + const totalPrice = tax + price; + return totalPrice; /* CURRENCY FORMATTING @@ -28,9 +31,9 @@ To run these tests type `node 4-tax.js` into your terminal function test(test_name, expr) { let status; if (expr) { - status = "PASSED"; + status = 'PASSED'; } else { - status = "FAILED"; + status = 'FAILED'; } console.log(`${test_name}: ${status}`); @@ -51,4 +54,6 @@ test( "formatCurrency function - case 2 works", formatCurrency(17.5) === "£21.00" ); -test("formatCurrency function - case 3 works", formatCurrency(34) === "£40.80"); +test( + "formatCurrency function - case 3 works", formatCurrency(34) + === "£40.80"); From f4d05d179eb6a4ba7f2f03c47cdd867948e8fb29 Mon Sep 17 00:00:00 2001 From: NihalAli2 <62475392+NihalAli2@users.noreply.github.com> Date: Sun, 21 Jun 2020 19:17:39 +0100 Subject: [PATCH 02/22] start exersise --- .../B-boolean-literals/exercise.js | 12 +-- .../C-comparison-operators/exercise.js | 7 +- week-2/1-exercises/D-predicates/exercise.js | 3 +- week-2/1-exercises/E-conditionals/exercise.js | 6 ++ .../F-logical-operators/exercise.js | 8 +- .../F-logical-operators/exercise2.js | 24 +++++- .../G-conditionals-2/exercise-1.js | 27 ++++++- .../G-conditionals-2/exercise-2.js | 27 ++++++- .../G-conditionals-2/exercise-3.js | 77 ++++++++++++++++++- 9 files changed, 173 insertions(+), 18 deletions(-) diff --git a/week-2/1-exercises/B-boolean-literals/exercise.js b/week-2/1-exercises/B-boolean-literals/exercise.js index 6c5060f..6bc05c6 100644 --- a/week-2/1-exercises/B-boolean-literals/exercise.js +++ b/week-2/1-exercises/B-boolean-literals/exercise.js @@ -5,12 +5,14 @@ Add the required variables with the correct boolean values assigned. */ -var codeYourFutureIsGreat = true; - -/* - DO NOT EDIT BELOW THIS LINE - --------------------------- */ +let codeYourFutureIsGreat = true; +let mozafarIsCool = false; +let calculationCorrect = true; +let moreThan10Students = false; + /* DO NOT EDIT BELOW THIS LINE + --------------------------- +*/ console.log("Is Code Your Future great?", codeYourFutureIsGreat); console.log("Is Mozafar cool?", mozafarIsCool); console.log("Does 1 + 1 = 2?", calculationCorrect); diff --git a/week-2/1-exercises/C-comparison-operators/exercise.js b/week-2/1-exercises/C-comparison-operators/exercise.js index 58aee1c..5086189 100644 --- a/week-2/1-exercises/C-comparison-operators/exercise.js +++ b/week-2/1-exercises/C-comparison-operators/exercise.js @@ -7,14 +7,15 @@ var studentCount = 16; var mentorCount = 9; -var moreStudentsThanMentors; // finish this statement +var sum = studentCount + mentorCount; +var moreStudentsThanMentors = studentCount > mentorCount; // finish this statement var roomMaxCapacity = 25; -var enoughSpaceInRoom; // finish this statement +var enoughSpaceInRoom = roomMaxCapacity === sum; // finish this statement var personA = "Daniel"; var personB = "Irina"; -var sameName; // finish this statement +var sameName = personA === personB; // finish this statement /* DO NOT EDIT BELOW THIS LINE diff --git a/week-2/1-exercises/D-predicates/exercise.js b/week-2/1-exercises/D-predicates/exercise.js index f600521..1b3df09 100644 --- a/week-2/1-exercises/D-predicates/exercise.js +++ b/week-2/1-exercises/D-predicates/exercise.js @@ -7,12 +7,13 @@ // Finish the predicate function to test if the passed number is negative (less than zero) function isNegative(number) { + return number > 0; } // Finish the predicate function to test if the passed number is between 0 and 10 function isBetweenZeroAnd10(number) { - +return number > 0 && number < 10; } /* diff --git a/week-2/1-exercises/E-conditionals/exercise.js b/week-2/1-exercises/E-conditionals/exercise.js index acbaaa8..363c612 100644 --- a/week-2/1-exercises/E-conditionals/exercise.js +++ b/week-2/1-exercises/E-conditionals/exercise.js @@ -8,6 +8,12 @@ var name = "Daniel"; var danielsRole = "mentor"; +if (danielsRole === `mentor`) { + console.log("Hi, I'm Daniel, I'm a mentor."); +} +else { + console.log("Hi, I'm Daniel, I'm a student."); +} /* EXPECTED RESULT diff --git a/week-2/1-exercises/F-logical-operators/exercise.js b/week-2/1-exercises/F-logical-operators/exercise.js index a8f2945..90469ca 100644 --- a/week-2/1-exercises/F-logical-operators/exercise.js +++ b/week-2/1-exercises/F-logical-operators/exercise.js @@ -11,14 +11,14 @@ var cssLevel = 4; // Finish the statement to check whether HTML, CSS knowledge are above 5 // (hint: use the comparison operator from before) -var htmlLevelAbove5; -var cssLevelAbove5; +var htmlLevelAbove5 = htmlLevel > 5; +var cssLevelAbove5 = cssLevel > 5; // Finish the next two statement // Use the previous variables and logical operators // Do not "hardcode" the answers -var cssAndHtmlAbove5; -var cssOrHtmlAbove5; +var cssAndHtmlAbove5 = htmlLevelAbove5 && cssLevelAbove5; +var cssOrHtmlAbove5 = htmlLevelAbove5 || cssLevelAbove5; /* DO NOT EDIT BELOW THIS LINE diff --git a/week-2/1-exercises/F-logical-operators/exercise2.js b/week-2/1-exercises/F-logical-operators/exercise2.js index 6f4199c..96bc021 100644 --- a/week-2/1-exercises/F-logical-operators/exercise2.js +++ b/week-2/1-exercises/F-logical-operators/exercise2.js @@ -5,7 +5,29 @@ Update the code so that you get the expected result. */ -function isNegative() {} +function isNegative(number) { +return number < 0; +} + + +function isNegative(number) { + return number < 0; + } + + + function isBetween5and10(number) { + return number >= 5 && number <= 10; + } + + + function isShortName(name) { + return name.length >= 6 && name.length <= 10; + } + + + function startsWithD(name) { + return name[0] === "D"; + } /* DO NOT EDIT BELOW THIS LINE diff --git a/week-2/1-exercises/G-conditionals-2/exercise-1.js b/week-2/1-exercises/G-conditionals-2/exercise-1.js index 54708ef..528233c 100644 --- a/week-2/1-exercises/G-conditionals-2/exercise-1.js +++ b/week-2/1-exercises/G-conditionals-2/exercise-1.js @@ -6,10 +6,33 @@ - if number is more or equal to zero, return the word "positive" */ -function negativeOrPositive(number) { - +function negativeOrPositive(number1) { +if (number1 < 0) { + return "negative"; +} +else { + return "positive"; +} } +function negativeOrPositive(number2) { + if (number2 < 0) { + return "negative"; + } + else { + return "positive"; + } + } + function negativeOrPositive(number3) { + if (number3 < 0) { + return "negative"; + } + else { + return "positive"; + } + } + + /* DO NOT EDIT BELOW THIS LINE --------------------------- */ diff --git a/week-2/1-exercises/G-conditionals-2/exercise-2.js b/week-2/1-exercises/G-conditionals-2/exercise-2.js index 313f3fb..52b22ce 100644 --- a/week-2/1-exercises/G-conditionals-2/exercise-2.js +++ b/week-2/1-exercises/G-conditionals-2/exercise-2.js @@ -7,8 +7,33 @@ */ -function studentPassed(grade) { +function studentPassed(grade1) { + if (grade1 < 50) { + return "failed"; + } +else { + return "passed"; +} +} + + +function studentPassed(grade2) { + if (grade2 < 50) { + return "failed"; + } +else { + return "passed"; +} +} + +function studentPassed(grade3) { + if (grade3 < 50) { + return "failed"; + } +else { + return "passed"; +} } /* diff --git a/week-2/1-exercises/G-conditionals-2/exercise-3.js b/week-2/1-exercises/G-conditionals-2/exercise-3.js index a79cf30..7273909 100644 --- a/week-2/1-exercises/G-conditionals-2/exercise-3.js +++ b/week-2/1-exercises/G-conditionals-2/exercise-3.js @@ -8,9 +8,84 @@ - Otherwise the grade is "F" */ -function calculateGrade(mark) { +function calculateGrade(grade1) { + if (grade1 >= 80) { + return "A"; + } +else if (grade1 < 80 && grade1 >60) { + return "B"; +} +else if (grade1 <= 60 && grade1 >= 50) { + return "C" +} +else { + return "F" +} +} +function calculateGrade(grade2) { + if (grade2 >= 80) { + return "A"; + } +else if (grade2 < 80 && grade2 >60) { + return "B"; +} +else if (grade2 <= 60 && grade2 >= 50) { + return "C" +} +else { + return "F" +} +} + + +function calculateGrade(grade3) { + if (grade3 >= 80) { + + return "A"; + } +else if (grade3 < 80 && grade3 >60) { + return "B"; +} +else if (grade3 <= 60 && grade3 >= 50) { + return "C" +} +else { + return "F" +} +} + + +function calculateGrade(grade4) { + if (grade4 >= 80) { + return "A"; + } +else if (grade4 < 80 && grade4 >60) { + return "B"; +} +else if (grade4 <= 60 && grade4 >= 50) { + return "C" +} +else { + return "F" +} +} + + +/*function calculateGrade(mark1) { + if (mark1 >= 80) { + return "A"; + } +else if (mark1 < 80 && mark1 >60) { + return "B"; +} +else if (mark1 === 60 || mark1 < 50) { + return "C" +} +else { + return "F" } +}*/ /* DO NOT EDIT BELOW THIS LINE From 72fc3075e9db853348ccf2114381e9154a2a53fe Mon Sep 17 00:00:00 2001 From: NihalAli2 <62475392+NihalAli2@users.noreply.github.com> Date: Mon, 22 Jun 2020 08:00:04 +0100 Subject: [PATCH 03/22] try diffrent method for exercise3 G --- .../G-conditionals-2/exercise-3.js | 32 ++++++++++--------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/week-2/1-exercises/G-conditionals-2/exercise-3.js b/week-2/1-exercises/G-conditionals-2/exercise-3.js index 7273909..08d3991 100644 --- a/week-2/1-exercises/G-conditionals-2/exercise-3.js +++ b/week-2/1-exercises/G-conditionals-2/exercise-3.js @@ -8,6 +8,21 @@ - Otherwise the grade is "F" */ +function calculateGrade(mark) { + if (mark >= 80) { + return "A"; + } +else if (mark < 80 && mark >60) { + return "B"; +} +else if (mark <= 60 && mark >= 50) { + return "C" +} +else { + return "F" +} +} +/* function calculateGrade(grade1) { if (grade1 >= 80) { return "A"; @@ -23,6 +38,7 @@ else { } } + function calculateGrade(grade2) { if (grade2 >= 80) { return "A"; @@ -69,23 +85,9 @@ else if (grade4 <= 60 && grade4 >= 50) { else { return "F" } -} +}*/ -/*function calculateGrade(mark1) { - if (mark1 >= 80) { - return "A"; - } -else if (mark1 < 80 && mark1 >60) { - return "B"; -} -else if (mark1 === 60 || mark1 < 50) { - return "C" -} -else { - return "F" -} -}*/ /* DO NOT EDIT BELOW THIS LINE From 7cf175c46122913705c19e2568ff9bbc6a30b411 Mon Sep 17 00:00:00 2001 From: NihalAli2 <62475392+NihalAli2@users.noreply.github.com> Date: Mon, 22 Jun 2020 08:06:16 +0100 Subject: [PATCH 04/22] Finish execise G --- week-2/1-exercises/G-conditionals-2/exercise-4.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/week-2/1-exercises/G-conditionals-2/exercise-4.js b/week-2/1-exercises/G-conditionals-2/exercise-4.js index bd5bb1e..4a4a7d2 100644 --- a/week-2/1-exercises/G-conditionals-2/exercise-4.js +++ b/week-2/1-exercises/G-conditionals-2/exercise-4.js @@ -10,6 +10,12 @@ function containsCode(sentence) { + if (sentence.includes("code")) { + return true; + } + else { + return false; + } } /* From 313fcb8e9186623aea8e826cd326205fb1f8c314 Mon Sep 17 00:00:00 2001 From: NihalAli2 <62475392+NihalAli2@users.noreply.github.com> Date: Mon, 22 Jun 2020 08:10:40 +0100 Subject: [PATCH 05/22] change exercise2 G --- week-2/1-exercises/G-conditionals-2/exercise-2.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/week-2/1-exercises/G-conditionals-2/exercise-2.js b/week-2/1-exercises/G-conditionals-2/exercise-2.js index 52b22ce..2f9fee9 100644 --- a/week-2/1-exercises/G-conditionals-2/exercise-2.js +++ b/week-2/1-exercises/G-conditionals-2/exercise-2.js @@ -7,6 +7,18 @@ */ +function studentPassed(grade) { + if (grade < 50) { + return "failed"; + } +else { + return "passed"; +} +} + + +/* + function studentPassed(grade1) { if (grade1 < 50) { return "failed"; @@ -17,6 +29,7 @@ else { } + function studentPassed(grade2) { if (grade2 < 50) { return "failed"; @@ -35,7 +48,7 @@ else { return "passed"; } } - +*/ /* DO NOT EDIT BELOW THIS LINE --------------------------- */ From 68bad6d03cfc752d8abeec7332aa624b7e883522 Mon Sep 17 00:00:00 2001 From: NihalAli2 <62475392+NihalAli2@users.noreply.github.com> Date: Mon, 22 Jun 2020 08:40:15 +0100 Subject: [PATCH 06/22] Finish exercises --- week-2/1-exercises/H-array-literals/exercise.js | 4 ++-- week-2/1-exercises/I-array-properties/exercise.js | 6 ++++-- week-2/1-exercises/J-array-get-set/exercise.js | 4 ++-- week-2/1-exercises/J-array-get-set/exercises2.js | 3 ++- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/week-2/1-exercises/H-array-literals/exercise.js b/week-2/1-exercises/H-array-literals/exercise.js index d6dc556..cf961ea 100644 --- a/week-2/1-exercises/H-array-literals/exercise.js +++ b/week-2/1-exercises/H-array-literals/exercise.js @@ -4,8 +4,8 @@ Declare some variables assigned to arrays of values */ -var numbers = []; // add numbers from 1 to 10 into this array -var mentors; // Create an array with the names of the mentors: Daniel, Irina and Rares +var numbers = [1, 2, 3, 4, 5, 6, 7, 7, 8, 9, 10]; // add numbers from 1 to 10 into this array +var mentors = ["Daniel", "Irina", "Rares"]; // Create an array with the names of the mentors: Daniel, Irina and Rares /* DO NOT EDIT BELOW THIS LINE diff --git a/week-2/1-exercises/I-array-properties/exercise.js b/week-2/1-exercises/I-array-properties/exercise.js index f9aec89..d05d607 100644 --- a/week-2/1-exercises/I-array-properties/exercise.js +++ b/week-2/1-exercises/I-array-properties/exercise.js @@ -6,8 +6,10 @@ */ function isEmpty(arr) { - return; // complete this statement -} + return arr.length == 0; + } + + /* DO NOT EDIT BELOW THIS LINE diff --git a/week-2/1-exercises/J-array-get-set/exercise.js b/week-2/1-exercises/J-array-get-set/exercise.js index 3b95694..18d072c 100644 --- a/week-2/1-exercises/J-array-get-set/exercise.js +++ b/week-2/1-exercises/J-array-get-set/exercise.js @@ -5,11 +5,11 @@ */ function first(arr) { - return; // complete this statement + return arr[0]; // complete this statement } function last(arr) { - return; // complete this statement + return arr[arr.length - 1]; // complete this statement } /* diff --git a/week-2/1-exercises/J-array-get-set/exercises2.js b/week-2/1-exercises/J-array-get-set/exercises2.js index 97f126f..962bcda 100644 --- a/week-2/1-exercises/J-array-get-set/exercises2.js +++ b/week-2/1-exercises/J-array-get-set/exercises2.js @@ -7,7 +7,8 @@ */ var numbers = [1, 2, 3]; // Don't change this array literal declaration - +numbers.push(4); +numbers[0]; /* DO NOT EDIT BELOW THIS LINE --------------------------- */ From b293b94184ff57975712808897c56a2031c00741 Mon Sep 17 00:00:00 2001 From: NihalAli2 <62475392+NihalAli2@users.noreply.github.com> Date: Mon, 22 Jun 2020 09:15:29 +0100 Subject: [PATCH 07/22] finish mandatory --- week-2/2-mandatory/1-fix-functions.js | 12 +++++----- week-2/2-mandatory/2-function-creation.js | 28 +++++++++++++++++++---- week-2/2-mandatory/3-playing-computer.js | 13 ++++++++++- week-2/2-mandatory/4-sorting-algorithm.js | 23 ++++++++++++++++++- 4 files changed, 64 insertions(+), 12 deletions(-) diff --git a/week-2/2-mandatory/1-fix-functions.js b/week-2/2-mandatory/1-fix-functions.js index 6316fad..56db952 100644 --- a/week-2/2-mandatory/1-fix-functions.js +++ b/week-2/2-mandatory/1-fix-functions.js @@ -4,7 +4,7 @@ function mood() { let isHappy = true; - if (isHappy) { + if (isHappy === false) { return "I am happy"; } else { return "I am not happy"; @@ -13,9 +13,9 @@ function mood() { function greaterThan10() { let num = 10; - let isBigEnough; + let isBigEnough = 11; - if (isBigEnough) { + if (isBigEnough >= 10) { return "num is greater than or equal to 10"; } else { return "num is not big enough"; @@ -24,21 +24,21 @@ function greaterThan10() { function sortArray() { let letters = ["a", "n", "c", "e", "z", "f"]; - let sortedLetters; + let sortedLetters = letters.sort(); return sortedLetters; } function first5() { let numbers = [1, 2, 3, 4, 5, 6, 7, 8]; - let sliced; + let sliced = numbers.slice(0, 5); return sliced; } function get3rdIndex(arr) { let index = 3; - let element; + let element = arr[index]; return element; } diff --git a/week-2/2-mandatory/2-function-creation.js b/week-2/2-mandatory/2-function-creation.js index bf7ecfd..0b66538 100644 --- a/week-2/2-mandatory/2-function-creation.js +++ b/week-2/2-mandatory/2-function-creation.js @@ -5,7 +5,10 @@ Write a function that: - removes any forward slashes (/) in the strings - makes the string all lowercase */ -function tidyUpString(strArr) {} +function tidyUpString(strArr) { + let tidyStrArr = strArr.map(item => item.trim().replace('/', '').toLowerCase()); + return tidyStrArr; +} /* Complete the function to check if the variable `num` satisfies the following requirements: @@ -15,7 +18,16 @@ Complete the function to check if the variable `num` satisfies the following req Tip: use logical operators */ -function validate(num) {} +function validate(num) { + let isNumber = typeof(num) === 'number'; + + let isEven = num % 2 == 0; + let isLessThanOrEqual100 = num <= 100; + if(isNumber && isEven && isLessThanOrEqual100) { + return true; + } + return false; +} /* Write a function that removes an element from an array @@ -26,7 +38,9 @@ The function must: */ function remove(arr, index) { - return; // complete this statement + let newArr = arr; + newArr.splice(index, 1); + return newArr; // complete this statement } /* @@ -38,7 +52,13 @@ Write a function that: */ function formatPercentage(arr) { - + let newArr = arr.map(item => { + if(item > 100){ + item = 100; + } + return `${Number(item.toFixed(2))}%`; + }) + return newArr; } /* ======= TESTS - DO NOT MODIFY ===== */ diff --git a/week-2/2-mandatory/3-playing-computer.js b/week-2/2-mandatory/3-playing-computer.js index 0fa7c04..49cd0e3 100644 --- a/week-2/2-mandatory/3-playing-computer.js +++ b/week-2/2-mandatory/3-playing-computer.js @@ -15,6 +15,17 @@ 7. What is the value of the "a" outer variable when "f1" is called for the first time? */ +/* +ANSWERS: +1. b, d and e is not defined; +2. removed: console.log(b); +3. Will be printed: 2, 6,4,9,6,13,8; +4. f1 is called 2 times; +5. f2 is called 3 times; +6. In the first f1 call a will be equal to 1; +7. The value of the "a" outer variable when 'f1' is called fir the first time is 8; +*/ + let x = 2; let a = 6; @@ -34,7 +45,7 @@ for (let i = 0; i < 5; ++i) { a = a + 1; if (i % 2 === 0) { const d = f2(i, x); - console.log(d); + //console.log(d); } else { const e = f1(i, a); console.log(e); diff --git a/week-2/2-mandatory/4-sorting-algorithm.js b/week-2/2-mandatory/4-sorting-algorithm.js index 3603942..b9211e6 100644 --- a/week-2/2-mandatory/4-sorting-algorithm.js +++ b/week-2/2-mandatory/4-sorting-algorithm.js @@ -14,7 +14,28 @@ You don't have to worry about making this algorithm work fast! The idea is to ge "think" like a computer and practice your knowledge of basic JavaScript. */ -function sortAges(arr) {} +function sortAges(arr) { + function sortAges(arr) { + let newArr = []; + let ok; + for(let i = 0; i < arr.length; i++){ + if(typeof(arr[i]) === 'number'){ + newArr.push(Number(arr[i])); + } + } + do{ + ok = false; + for(let i = 0; i < newArr.length; i++){ + if(newArr[i+1] < newArr[i]){ + let aux = newArr[i]; + newArr[i] = newArr[i+1]; + newArr[i+1] = aux; + ok =true; + } + } + }while(ok); + return newArr; +} /* ======= TESTS - DO NOT MODIFY ===== */ From 13cc22c44107f1eaa3b907268176cd083395ada7 Mon Sep 17 00:00:00 2001 From: NihalAli2 <62475392+NihalAli2@users.noreply.github.com> Date: Thu, 25 Jun 2020 20:04:55 +0100 Subject: [PATCH 08/22] new add --- week-2/2-mandatory/4-sorting-algorithm.js | 4 ++-- week-3/1-exercises/test.js | 0 2 files changed, 2 insertions(+), 2 deletions(-) create mode 100644 week-3/1-exercises/test.js diff --git a/week-2/2-mandatory/4-sorting-algorithm.js b/week-2/2-mandatory/4-sorting-algorithm.js index b9211e6..a860ed3 100644 --- a/week-2/2-mandatory/4-sorting-algorithm.js +++ b/week-2/2-mandatory/4-sorting-algorithm.js @@ -14,13 +14,13 @@ You don't have to worry about making this algorithm work fast! The idea is to ge "think" like a computer and practice your knowledge of basic JavaScript. */ -function sortAges(arr) { + function sortAges(arr) { let newArr = []; let ok; for(let i = 0; i < arr.length; i++){ if(typeof(arr[i]) === 'number'){ - newArr.push(Number(arr[i])); + newArr.push((arr[i])); } } do{ diff --git a/week-3/1-exercises/test.js b/week-3/1-exercises/test.js new file mode 100644 index 0000000..e69de29 From 1657f7c4a67ab8ec34b8d3f18d10e4472c5f2dfd Mon Sep 17 00:00:00 2001 From: NihalAli2 <62475392+NihalAli2@users.noreply.github.com> Date: Thu, 25 Jun 2020 23:24:59 +0100 Subject: [PATCH 09/22] Change Mandatory2 --- week-2/2-mandatory/2-function-creation.js | 20 +++++++++++-- week-2/2-mandatory/4-sorting-algorithm.js | 34 +++++++++++++++++++---- 2 files changed, 46 insertions(+), 8 deletions(-) diff --git a/week-2/2-mandatory/2-function-creation.js b/week-2/2-mandatory/2-function-creation.js index 0b66538..9cf2ed3 100644 --- a/week-2/2-mandatory/2-function-creation.js +++ b/week-2/2-mandatory/2-function-creation.js @@ -51,7 +51,7 @@ Write a function that: - numbers greater 100 must be replaced with 100 */ -function formatPercentage(arr) { +/*function formatPercentage(arr) { let newArr = arr.map(item => { if(item > 100){ item = 100; @@ -59,7 +59,23 @@ function formatPercentage(arr) { return `${Number(item.toFixed(2))}%`; }) return newArr; -} +}*/ + +function formatPercentage(arr) { + for( let i = 0; i < arr.length; i++){ + if (arr[i] > 100){ + arr[i] = 100; + } + let j = arr[i].toFixed(2) + j = parseFloat(j); + arr[i] = j.toString() + "%"; + } + return arr; + } + + + + /* ======= TESTS - DO NOT MODIFY ===== */ diff --git a/week-2/2-mandatory/4-sorting-algorithm.js b/week-2/2-mandatory/4-sorting-algorithm.js index a860ed3..450d0d3 100644 --- a/week-2/2-mandatory/4-sorting-algorithm.js +++ b/week-2/2-mandatory/4-sorting-algorithm.js @@ -15,28 +15,50 @@ You don't have to worry about making this algorithm work fast! The idea is to ge */ - function sortAges(arr) { +function sortAges(arr) { + let swap; + let arr1 = []; + for (let i = 0; i < arr.length; i++){ + if (typeof(arr[i] === "number")){ + arr1.push(arr[i]) + } + } + for (i = 0; i < arr1.length; i++){ + for (let j = i+1; j < arr1.length; j++){ + if (arr1 [j] < arr1[i] + ){ +swap = arr1[i]; +arr1[i] = arr1[j]; +arr1[j]= swap; + } + } + } + return arr1; +} + + + /*function sortAges(arr) { let newArr = []; - let ok; + let arr1; for(let i = 0; i < arr.length; i++){ if(typeof(arr[i]) === 'number'){ newArr.push((arr[i])); } } do{ - ok = false; + arr1 = false; for(let i = 0; i < newArr.length; i++){ if(newArr[i+1] < newArr[i]){ let aux = newArr[i]; newArr[i] = newArr[i+1]; newArr[i+1] = aux; - ok =true; + arr =true; } } - }while(ok); + }while(arr1); return newArr; } - +*/ /* ======= TESTS - DO NOT MODIFY ===== */ const agesCase1 = [ From 42502559d1ef59c30a05f291c9514a76257989fb Mon Sep 17 00:00:00 2001 From: NihalAli2 <62475392+NihalAli2@users.noreply.github.com> Date: Fri, 26 Jun 2020 14:15:12 +0100 Subject: [PATCH 10/22] sorting-algorithm --- week-2/2-mandatory/3-playing-computer.js | 2 +- week-2/2-mandatory/4-sorting-algorithm.js | 48 ++++++----------------- 2 files changed, 14 insertions(+), 36 deletions(-) diff --git a/week-2/2-mandatory/3-playing-computer.js b/week-2/2-mandatory/3-playing-computer.js index 49cd0e3..4b4bccd 100644 --- a/week-2/2-mandatory/3-playing-computer.js +++ b/week-2/2-mandatory/3-playing-computer.js @@ -39,7 +39,7 @@ const f2 = function(a, b) { console.log(x); console.log(a); -console.log(b); +//console.log(b); for (let i = 0; i < 5; ++i) { a = a + 1; diff --git a/week-2/2-mandatory/4-sorting-algorithm.js b/week-2/2-mandatory/4-sorting-algorithm.js index 450d0d3..041eff3 100644 --- a/week-2/2-mandatory/4-sorting-algorithm.js +++ b/week-2/2-mandatory/4-sorting-algorithm.js @@ -7,58 +7,36 @@ Today, you will be applying the sorting algorithm you used in that exercise in c Create a function called sortAges which: - takes an array of mixed data types as input - removes any non-number data types without using the built-in javascript filter method -- returns an array of sorted ages in ascending order +- eturnrs an array of sorted ages in ascending order - HARD MODE - without using the built-in javascript sort method 😎 You don't have to worry about making this algorithm work fast! The idea is to get you to "think" like a computer and practice your knowledge of basic JavaScript. */ - function sortAges(arr) { - let swap; - let arr1 = []; + //let swap; + let newArr = []; for (let i = 0; i < arr.length; i++){ - if (typeof(arr[i] === "number")){ - arr1.push(arr[i]) + if (typeof(arr[i]) === "number"){ + newArr.push(arr[i]); } } - for (i = 0; i < arr1.length; i++){ - for (let j = i+1; j < arr1.length; j++){ - if (arr1 [j] < arr1[i] + for (i = 0; i < newArr.length; i++){ + for (let j = i+1; j < newArr.length; j++){ + if (newArr[j] < newArr[i] ){ -swap = arr1[i]; -arr1[i] = arr1[j]; -arr1[j]= swap; +swap = newArr[i]; +newArr[i] = newArr[j]; +newArr[j]= swap; } } } - return arr1; + return newArr; } - /*function sortAges(arr) { - let newArr = []; - let arr1; - for(let i = 0; i < arr.length; i++){ - if(typeof(arr[i]) === 'number'){ - newArr.push((arr[i])); - } - } - do{ - arr1 = false; - for(let i = 0; i < newArr.length; i++){ - if(newArr[i+1] < newArr[i]){ - let aux = newArr[i]; - newArr[i] = newArr[i+1]; - newArr[i+1] = aux; - arr =true; - } - } - }while(arr1); - return newArr; -} -*/ + /* ======= TESTS - DO NOT MODIFY ===== */ const agesCase1 = [ From 82644d241ff17db2c900856797892f954ac6c9c9 Mon Sep 17 00:00:00 2001 From: NihalAli2 <62475392+NihalAli2@users.noreply.github.com> Date: Fri, 26 Jun 2020 21:35:12 +0100 Subject: [PATCH 11/22] Extra --- week-2/3-extra/1-radio-stations.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/week-2/3-extra/1-radio-stations.js b/week-2/3-extra/1-radio-stations.js index 95c0e56..7948820 100644 --- a/week-2/3-extra/1-radio-stations.js +++ b/week-2/3-extra/1-radio-stations.js @@ -26,6 +26,11 @@ */ // `getStations` goes here +function getAllFrequencies(list) { + var freq = [] + +} + /* ======= TESTS - DO NOT MODIFY ======= */ From 9a8b53ad4c80aa158245beda60ae80b516218e00 Mon Sep 17 00:00:00 2001 From: NihalAli2 <62475392+NihalAli2@users.noreply.github.com> Date: Fri, 26 Jun 2020 22:04:33 +0100 Subject: [PATCH 12/22] Exercise-A --- week-3/1-exercises/A-array-find/exercise.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/week-3/1-exercises/A-array-find/exercise.js b/week-3/1-exercises/A-array-find/exercise.js index d7fd51f..9194741 100644 --- a/week-3/1-exercises/A-array-find/exercise.js +++ b/week-3/1-exercises/A-array-find/exercise.js @@ -5,11 +5,16 @@ // write your code here -var names = ["Rakesh", "Antonio", "Alexandra", "Andronicus", "Annam", "Mikey", "Anastasia", "Karim", "Ahmed"]; - -var longNameThatStartsWithA = findLongNameThatStartsWithA(names); -console.log(longNameThatStartsWithA); +function longNameThatStartsWithA(nams) { + return (nams.length > 7 && nams.charAt(0) === "A"); +} +var names = ["Rakesh", "Antonio", "Alexandra", "Andronicus", "Annam", "Mikey", "Anastasia", "Karim", "Ahmed"]; +let firstnames = names.find(longNameThatStartsWithA); +console.log(firstnames); +/*var longNameThatStartsWithA = findLongNameThatStartsWithA(names); +} +console.log(); /* EXPECTED OUTPUT */ -// "Alexandra" +// "Alexandra"*/ From 59907cab1e4e1b3539b7cf4ad15a6060a60a5711 Mon Sep 17 00:00:00 2001 From: NihalAli2 <62475392+NihalAli2@users.noreply.github.com> Date: Fri, 26 Jun 2020 22:38:36 +0100 Subject: [PATCH 13/22] Exercise-array-some --- week-3/1-exercises/B-array-some/exercise.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/week-3/1-exercises/B-array-some/exercise.js b/week-3/1-exercises/B-array-some/exercise.js index 965c052..119abea 100644 --- a/week-3/1-exercises/B-array-some/exercise.js +++ b/week-3/1-exercises/B-array-some/exercise.js @@ -12,12 +12,17 @@ var pairsByIndex = [[0, 3], [1, 2], [2, 1], null, [3, 0]]; // https://nodejs.org/api/process.html#process_process_exit_code // process.exit(1); + var students = ["Islam", "Lesley", "Harun", "Rukmini"]; var mentors = ["Daniel", "Irina", "Mozafar", "Luke"]; var pairs = pairsByIndex.map(function(indexes) { + if (indexes === null) { + process.exit(1); + } var student = students[indexes[0]]; var mentor = mentors[indexes[1]]; + return [student, mentor]; }); From d2cacbc42673cf02ef4b46985d72ed9a9993c224 Mon Sep 17 00:00:00 2001 From: NihalAli2 <62475392+NihalAli2@users.noreply.github.com> Date: Sat, 27 Jun 2020 10:42:50 +0100 Subject: [PATCH 14/22] changes --- week-3/1-exercises/C-array-every/exercise.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/week-3/1-exercises/C-array-every/exercise.js b/week-3/1-exercises/C-array-every/exercise.js index b515e94..4e47fe9 100644 --- a/week-3/1-exercises/C-array-every/exercise.js +++ b/week-3/1-exercises/C-array-every/exercise.js @@ -5,9 +5,12 @@ var students = ["Omar", "Austine", "Dany", "Swathi", "Lesley", "Rukmini"]; var group = ["Austine", "Dany", "Swathi", "Daniel"]; -var groupIsOnlyStudents; // complete this statement +function groups(arr) { + return (arr.includes) +} +var groupIsOnlyStudents = students.includes(group); // complete this statement -if (groupIsOnlyStudents) { +if (groupIsOnlyStudents.every(group)) { console.log("The group contains only students"); } else { console.log("The group does not contain only students"); From c04fbdc8f03bf0422a549c544df72da53a1c2711 Mon Sep 17 00:00:00 2001 From: NihalAli2 <62475392+NihalAli2@users.noreply.github.com> Date: Tue, 30 Jun 2020 12:29:43 +0100 Subject: [PATCH 15/22] new changes --- week-3/1-exercises/C-array-every/exercise.js | 30 +++++++++++++++++--- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/week-3/1-exercises/C-array-every/exercise.js b/week-3/1-exercises/C-array-every/exercise.js index 4e47fe9..d809683 100644 --- a/week-3/1-exercises/C-array-every/exercise.js +++ b/week-3/1-exercises/C-array-every/exercise.js @@ -1,21 +1,43 @@ /* + This program should check if the array `group` contains only students + */ + + var students = ["Omar", "Austine", "Dany", "Swathi", "Lesley", "Rukmini"]; + var group = ["Austine", "Dany", "Swathi", "Daniel"]; -function groups(arr) { - return (arr.includes) + // complete this statement + var groupIsOnlyStudents = group.every(students); + +function studentArrey(arr) { + + + return studentArrey(groupIsOnlyStudents); } -var groupIsOnlyStudents = students.includes(group); // complete this statement -if (groupIsOnlyStudents.every(group)) { +if (groupIsOnlyStudents) { + console.log("The group contains only students"); + } else { + console.log("The group does not contain only students"); + } + + /* EXPECTED RESULT */ + + // The group does not contain only students + + +// var studentNameLength = students.every(isAboveThreshold); + +// console.log(studentNameLength); // logs true \ No newline at end of file From dcf09fccc66bd03998c70ab2ac8f60c8f6439277 Mon Sep 17 00:00:00 2001 From: NihalAli2 <62475392+NihalAli2@users.noreply.github.com> Date: Wed, 1 Jul 2020 21:10:16 +0100 Subject: [PATCH 16/22] oxygen-level --- week-3/1-exercises/test.js | 0 week-3/2-mandatory/1-oxygen-levels.js | 11 +++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) delete mode 100644 week-3/1-exercises/test.js diff --git a/week-3/1-exercises/test.js b/week-3/1-exercises/test.js deleted file mode 100644 index e69de29..0000000 diff --git a/week-3/2-mandatory/1-oxygen-levels.js b/week-3/2-mandatory/1-oxygen-levels.js index 3c02135..754c10b 100644 --- a/week-3/2-mandatory/1-oxygen-levels.js +++ b/week-3/2-mandatory/1-oxygen-levels.js @@ -9,9 +9,16 @@ To be safe, they need to land on the first unamed planet that has Oxygen levels Write a function that finds the oxygen level of the first safe planet - Oxygen between 19.5% and 23.5% */ -function safeLevels() { -} + function safeLevels(oxygenLevels) { + let safeLevels = oxygenLevels.find(oxygenLevel =>{ + if (oxygenLevel > `19.5%` && oxygenLevel < `23.5%`){ + return oxygenLevel; + } + }) + return safeLevels; + } + /* ======= TESTS - DO NOT MODIFY ===== */ From 3a66397fc8fffdb0e76d94f2e4859fd59a1c1d1a Mon Sep 17 00:00:00 2001 From: NihalAli2 <62475392+NihalAli2@users.noreply.github.com> Date: Wed, 1 Jul 2020 21:35:46 +0100 Subject: [PATCH 17/22] bush-berries and space-colonies --- week-3/2-mandatory/2-bush-berries.js | 8 ++++++-- week-3/2-mandatory/3-space-colonies.js | 10 +++++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/week-3/2-mandatory/2-bush-berries.js b/week-3/2-mandatory/2-bush-berries.js index d900323..e3a5f1f 100644 --- a/week-3/2-mandatory/2-bush-berries.js +++ b/week-3/2-mandatory/2-bush-berries.js @@ -10,8 +10,12 @@ Use the tests to confirm which message to return */ -function bushChecker() { - +function bushChecker(arr) { + let berry = arr.every(x => x==="pink"); + if (berry === true) { + return "Bush is safe to eat from"; + } + return "Toxic! Leave bush alone!"; } /* ======= TESTS - DO NOT MODIFY ===== */ diff --git a/week-3/2-mandatory/3-space-colonies.js b/week-3/2-mandatory/3-space-colonies.js index f99891a..33d75d7 100644 --- a/week-3/2-mandatory/3-space-colonies.js +++ b/week-3/2-mandatory/3-space-colonies.js @@ -8,7 +8,15 @@ NOTE: don't include any element that is not a "family". */ -function colonisers() { + +/*function colonisers(arr) { +let safefamily =arr.filter(x=> x.length > 9 && x.charAt(0) ==="A"); +return safefamily; +}*/ + +function colonisers(arr) { + let family = arr.filter(x=> x.length > 9 && x.charAt(0) === "A"); + return family; } From 21b7e27296183f7138c6319416eadbf8131e5a16 Mon Sep 17 00:00:00 2001 From: NihalAli2 <62475392+NihalAli2@users.noreply.github.com> Date: Fri, 3 Jul 2020 23:37:22 +0100 Subject: [PATCH 18/22] New homework --- week-3/2-mandatory/3-space-colonies.js | 5 +---- week-3/2-mandatory/4-eligible-students.js | 11 ++++++++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/week-3/2-mandatory/3-space-colonies.js b/week-3/2-mandatory/3-space-colonies.js index 33d75d7..a5dbc2e 100644 --- a/week-3/2-mandatory/3-space-colonies.js +++ b/week-3/2-mandatory/3-space-colonies.js @@ -9,10 +9,7 @@ */ -/*function colonisers(arr) { -let safefamily =arr.filter(x=> x.length > 9 && x.charAt(0) ==="A"); -return safefamily; -}*/ + function colonisers(arr) { let family = arr.filter(x=> x.length > 9 && x.charAt(0) === "A"); diff --git a/week-3/2-mandatory/4-eligible-students.js b/week-3/2-mandatory/4-eligible-students.js index 6424b01..e93e283 100644 --- a/week-3/2-mandatory/4-eligible-students.js +++ b/week-3/2-mandatory/4-eligible-students.js @@ -7,9 +7,14 @@ - Returns an array containing only the names of the who have attended AT LEAST 8 classes */ -function eligibleStudents() { - -} +function eligibleStudents(studentWork) { +let studentWhoCanSitExam = []; +for (i = 0; i <= studentWork.length; i++) + if (studentWork[i][1]) >= 8){ + studentWhoCanSitExam.push(studentWork[i][0]); + } +} +return studentWhoCanSitExam; /* ======= TESTS - DO NOT MODIFY ===== */ From eeec613d8c2c87498830855e40b642ec755fe9ab Mon Sep 17 00:00:00 2001 From: NihalAli2 <62475392+NihalAli2@users.noreply.github.com> Date: Sun, 5 Jul 2020 13:18:03 +0100 Subject: [PATCH 19/22] New Changes --- week-3/2-mandatory/4-eligible-students.js | 13 +++++++------ week-3/2-mandatory/5-journey-planner.js | 10 +++++++++- week-3/2-mandatory/6-lane-names.js | 8 ++++++-- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/week-3/2-mandatory/4-eligible-students.js b/week-3/2-mandatory/4-eligible-students.js index e93e283..99d3730 100644 --- a/week-3/2-mandatory/4-eligible-students.js +++ b/week-3/2-mandatory/4-eligible-students.js @@ -8,14 +8,15 @@ */ function eligibleStudents(studentWork) { -let studentWhoCanSitExam = []; -for (i = 0; i <= studentWork.length; i++) - if (studentWork[i][1]) >= 8){ - studentWhoCanSitExam.push(studentWork[i][0]); + let studentWhoCanSitExam = []; +for (i = 0; i <= studentWork.length; i++) + + if (studentWork[i][1] >= 8){ + studentWhoCanSitExam.push(studentWork[i][0]); } -} -return studentWhoCanSitExam; +return studentWhoCanSitExam; +} /* ======= TESTS - DO NOT MODIFY ===== */ const attendances = [ diff --git a/week-3/2-mandatory/5-journey-planner.js b/week-3/2-mandatory/5-journey-planner.js index 53499c3..88c4f6a 100644 --- a/week-3/2-mandatory/5-journey-planner.js +++ b/week-3/2-mandatory/5-journey-planner.js @@ -7,8 +7,16 @@ NOTE: only the names should be returned, not the means of transport. */ -function journeyPlanner() { + +function journeyPlanner(location, transport) { + let avilabelLocations = []; +for (i = 0; i < location.length; i++) { + if (location[i].includes(transport)) { + avilabelLocations.push(location[i][0]); + } +} +return avilabelLocations; } /* ======= TESTS - DO NOT MODIFY ===== */ diff --git a/week-3/2-mandatory/6-lane-names.js b/week-3/2-mandatory/6-lane-names.js index eddfe44..e0a05cb 100644 --- a/week-3/2-mandatory/6-lane-names.js +++ b/week-3/2-mandatory/6-lane-names.js @@ -4,8 +4,12 @@ Write a function that will return all street names which contain 'Lane' in their name. */ -function getLanes() { - +function Lane(arr) { +return arr.includes("lane"); +} +function getLanes(streetNames) { + let result = streetNames.filter(lane); + return result; } /* ======= TESTS - DO NOT MODIFY ===== */ From 711823c71a584ee193780763229267b0471144da Mon Sep 17 00:00:00 2001 From: NihalAli2 <62475392+NihalAli2@users.noreply.github.com> Date: Sun, 5 Jul 2020 22:43:30 +0100 Subject: [PATCH 20/22] Update mandatory week3 --- week-3/2-mandatory/6-lane-names.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/week-3/2-mandatory/6-lane-names.js b/week-3/2-mandatory/6-lane-names.js index e0a05cb..439e709 100644 --- a/week-3/2-mandatory/6-lane-names.js +++ b/week-3/2-mandatory/6-lane-names.js @@ -4,14 +4,17 @@ Write a function that will return all street names which contain 'Lane' in their name. */ -function Lane(arr) { -return arr.includes("lane"); +function getLanes(arr) { +return arr.includes("Lane"); } -function getLanes(streetNames) { - let result = streetNames.filter(lane); +function lans(streetNames) { + let result = streetNames.filter("Lane"); return result; } + + + /* ======= TESTS - DO NOT MODIFY ===== */ const streetNames = [ From c7ff1b34305609f4c25bc535099b5585500c22e1 Mon Sep 17 00:00:00 2001 From: NihalAli2 <62475392+NihalAli2@users.noreply.github.com> Date: Mon, 6 Jul 2020 07:17:07 +0100 Subject: [PATCH 21/22] Finish Mandatory Week3 --- week-3/2-mandatory/1-oxygen-levels.js | 10 +++---- week-3/2-mandatory/4-eligible-students.js | 4 +-- week-3/2-mandatory/7-password-validator.js | 32 +++++++++++++++++++++- 3 files changed, 38 insertions(+), 8 deletions(-) diff --git a/week-3/2-mandatory/1-oxygen-levels.js b/week-3/2-mandatory/1-oxygen-levels.js index 754c10b..35de4ed 100644 --- a/week-3/2-mandatory/1-oxygen-levels.js +++ b/week-3/2-mandatory/1-oxygen-levels.js @@ -10,13 +10,13 @@ Write a function that finds the oxygen level of the first safe planet - Oxygen b */ - function safeLevels(oxygenLevels) { - let safeLevels = oxygenLevels.find(oxygenLevel =>{ - if (oxygenLevel > `19.5%` && oxygenLevel < `23.5%`){ - return oxygenLevel; + function safeLevels(oxygen) { + let safety = oxygen.find(oxygen =>{ + if (oxygen > `19.5%` && oxygen < `23.5%`){ + return oxygen; } }) - return safeLevels; + return safety; } diff --git a/week-3/2-mandatory/4-eligible-students.js b/week-3/2-mandatory/4-eligible-students.js index 99d3730..e5c0449 100644 --- a/week-3/2-mandatory/4-eligible-students.js +++ b/week-3/2-mandatory/4-eligible-students.js @@ -9,9 +9,9 @@ function eligibleStudents(studentWork) { let studentWhoCanSitExam = []; -for (i = 0; i <= studentWork.length; i++) +for (let i = 0; i <= studentWork.length; i++); - if (studentWork[i][1] >= 8){ + if (studentWork[i][1] >= 8 ){ studentWhoCanSitExam.push(studentWork[i][0]); } diff --git a/week-3/2-mandatory/7-password-validator.js b/week-3/2-mandatory/7-password-validator.js index 57b3d53..40a41eb 100644 --- a/week-3/2-mandatory/7-password-validator.js +++ b/week-3/2-mandatory/7-password-validator.js @@ -22,9 +22,39 @@ PasswordValidationResult= [false, false, false, false, true] */ -function validatePasswords(passwords) { +// function validatePasswords(passwords) { + +// } +function fiveOrMoreLetters(word) { + return word.length >= 5; +} +function checkUpperCase(word) { +let regex = /[A-Z]/; +return regex.test(word); +} +function checkLowerCase(word) { +let regex = /[a-z]/; +return regex.test(word); +} +function checkNumbers(word) { +let regex = /[0-9]/; +return regex.test(word); } +function checkSymbols(word) { +let regex = /[!#$%.*&]/; +return regex.test(word); +} +// function containsRepeat(word) { +// } +function validatePasswords(passwords) { +return passwords.map(word => fiveOrMoreLetters(word) +&& checkUpperCase(word) +&& checkLowerCase(word) +&& checkNumbers(word) +&& checkSymbols(word)); +} + /* ======= TESTS - DO NOT MODIFY ===== */ From 5caee6766c86017aac9b426eb60e9b25dfc2a470 Mon Sep 17 00:00:00 2001 From: NihalAli2 <62475392+NihalAli2@users.noreply.github.com> Date: Mon, 6 Jul 2020 20:54:20 +0100 Subject: [PATCH 22/22] Change mandotory 4 and 6 --- week-3/2-mandatory/4-eligible-students.js | 21 ++++++++++++++------- week-3/2-mandatory/6-lane-names.js | 19 ++++++++++++------- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/week-3/2-mandatory/4-eligible-students.js b/week-3/2-mandatory/4-eligible-students.js index e5c0449..b49e468 100644 --- a/week-3/2-mandatory/4-eligible-students.js +++ b/week-3/2-mandatory/4-eligible-students.js @@ -7,16 +7,23 @@ - Returns an array containing only the names of the who have attended AT LEAST 8 classes */ -function eligibleStudents(studentWork) { - let studentWhoCanSitExam = []; -for (let i = 0; i <= studentWork.length; i++); - if (studentWork[i][1] >= 8 ){ - studentWhoCanSitExam.push(studentWork[i][0]); - } -return studentWhoCanSitExam; +function eligibleStudents(arr) { + let result = arr.filter(checkTheAtendace); + function checkTheAtendace(students) { + return students[1] >= 8; + } +console.log(result); + let getStudent = result.map(bringNames); + function bringNames(students) { + return students[0]; + } +console.log(getStudent); +return getStudent; } + + /* ======= TESTS - DO NOT MODIFY ===== */ const attendances = [ diff --git a/week-3/2-mandatory/6-lane-names.js b/week-3/2-mandatory/6-lane-names.js index 439e709..6c1c5d8 100644 --- a/week-3/2-mandatory/6-lane-names.js +++ b/week-3/2-mandatory/6-lane-names.js @@ -4,16 +4,21 @@ Write a function that will return all street names which contain 'Lane' in their name. */ -function getLanes(arr) { -return arr.includes("Lane"); -} -function lans(streetNames) { - let result = streetNames.filter("Lane"); - return result; -} +function getLanes(arr) { + let street = []; //blank array to push the new values in + let lane = arr.map(element => element.indexOf("Lane")); + for(let i = 0; i < arr.length; i++) { + if (lane[i] !== -1) { + street.push(arr[i]); + } + } + return street; +} + + /* ======= TESTS - DO NOT MODIFY ===== */