From d009f8239c4f9f5a2702008142733479adb59237 Mon Sep 17 00:00:00 2001 From: zubeda Date: Wed, 17 Jun 2020 11:37:00 +0100 Subject: [PATCH 01/17] update pull request --- .github/pull_request_template.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 696fd85..0f7b56c 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -1,7 +1,7 @@ # Your Details -Your Name: -Your City: +Your Name:zubeda +Your City:birminghan Your Slack Name: # Homework Details From c91bfe10e4aededb2d59e46b0bd169db1c905bfa Mon Sep 17 00:00:00 2001 From: zubeda Date: Wed, 17 Jun 2020 11:41:55 +0100 Subject: [PATCH 02/17] new upstream upstream1 --- .github/pull_request_template.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 0f7b56c..c7da2f1 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -3,8 +3,6 @@ Your Name:zubeda Your City:birminghan Your Slack Name: - # Homework Details - Module: Week: From 77d2ae158630cb0748b29fdc7cdf92be8be88c3f Mon Sep 17 00:00:00 2001 From: zubeda Date: Wed, 17 Jun 2020 13:15:36 +0100 Subject: [PATCH 03/17] syntax-error.js file is done --- week-1/2-mandatory/1-syntax-errors.js | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/week-1/2-mandatory/1-syntax-errors.js b/week-1/2-mandatory/1-syntax-errors.js index 6910f28..311ec6a 100644 --- a/week-1/2-mandatory/1-syntax-errors.js +++ b/week-1/2-mandatory/1-syntax-errors.js @@ -2,18 +2,20 @@ // 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"; +function introduceMe(name, age){ +return "Hello, my name is " + name + " and I am " + age + " years old"; +} -function getAddition(a, b) { - total = a ++ b +function getRemainder(a, b) { + // Use string interpolation here - return "The total is %{total}" + let Reminder=a%b; + return `The remainder is ${a%b}`; } /* ======= TESTS - DO NOT MODIFY ===== */ @@ -23,14 +25,14 @@ function getAddition(a, b) { 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 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"); \ No newline at end of file From 6e65b44ea5a349c4d5be0f438f8e58f67558cedb Mon Sep 17 00:00:00 2001 From: zubeda Date: Wed, 17 Jun 2020 13:33:43 +0100 Subject: [PATCH 04/17] 2-logic-error.js is done --- week-1/2-mandatory/2-logic-error.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/week-1/2-mandatory/2-logic-error.js b/week-1/2-mandatory/2-logic-error.js index 1e0a9d4..10bfe3b 100644 --- a/week-1/2-mandatory/2-logic-error.js +++ b/week-1/2-mandatory/2-logic-error.js @@ -1,16 +1,16 @@ // 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 +22,14 @@ 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 From b55ae4a1cf5ae1cc4d03a1c0868eadab92183084 Mon Sep 17 00:00:00 2001 From: zubeda Date: Wed, 17 Jun 2020 14:00:18 +0100 Subject: [PATCH 05/17] 3-function-output.js is done --- week-1/2-mandatory/3-function-output.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/week-1/2-mandatory/3-function-output.js b/week-1/2-mandatory/3-function-output.js index bbb88a2..5faaf7b 100644 --- a/week-1/2-mandatory/3-function-output.js +++ b/week-1/2-mandatory/3-function-output.js @@ -1,16 +1,17 @@ // Add comments to explain what this function does. You're meant to use Google! -function getNumber() { +function getNumber() {//MAth.random()*10 return random numbers between 1 and 10 return Math.random() * 10; } // Add comments to explain what this function does. You're meant to use Google! -function s(w1, w2) { +function s(w1, w2) {//w1.concat(w2) return a new string containing the text of joined string 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 + + console.log(firstWord.concat(" ").concat(secondWord).concat(" ").concat(thirdWord)); + return firstWord.concat(" ").concat(secondWord).concat(" ").concat(thirdWord); } /* ======= TESTS - DO NOT MODIFY ===== @@ -34,10 +35,12 @@ 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" From bc62e64bc76e52fc3e1bc567b4c0a81d0750f1c4 Mon Sep 17 00:00:00 2001 From: zubeda Date: Wed, 17 Jun 2020 20:21:27 +0100 Subject: [PATCH 06/17] 4-taxt.js is done --- week-1/2-mandatory/4-tax.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/week-1/2-mandatory/4-tax.js b/week-1/2-mandatory/4-tax.js index 6b84208..6112dd9 100644 --- a/week-1/2-mandatory/4-tax.js +++ b/week-1/2-mandatory/4-tax.js @@ -5,7 +5,11 @@ Sales tax is 20% of the price of the product */ -function calculateSalesTax() {} +function calculateSalesTax(priceOfProduct) { + + let salesTax=(20/100*priceOfProduct)+priceOfProduct; + return salesTax; +} /* CURRENCY FORMATTING @@ -17,7 +21,11 @@ function calculateSalesTax() {} Remember that the prices must include the sales tax (hint: you already wrote a function for this!) */ -function formatCurrency() {} +function formatCurrency(a) { +var price=calculateSalesTax(a); + +return `£${price.toFixed(2)}`; +} /* ======= TESTS - DO NOT MODIFY ===== There are some Tests in this file that will help you work out if your code is working. From f04cfa53d349e4d8759b1b969e6985f2ed923c8e Mon Sep 17 00:00:00 2001 From: zubeda Date: Thu, 18 Jun 2020 04:52:46 +0100 Subject: [PATCH 07/17] 3-extra>1-currency-conversion is done --- week-1/3-extra/1-currency-conversion.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/week-1/3-extra/1-currency-conversion.js b/week-1/3-extra/1-currency-conversion.js index 7f321d9..4177082 100644 --- a/week-1/3-extra/1-currency-conversion.js +++ b/week-1/3-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(price) { + let convertToUs=1.4*price;; + return convertToUs; +} /* CURRENCY FORMATTING @@ -16,7 +19,12 @@ function convertToUSD() {} Find a way to add 1% to all currency conversions (think about the DRY principle) */ -function convertToBRL() {} +function convertToBRL(price) { + let percentOfPrice=(1/100)*(5.7*price); + let convertToBrazil=5.7*price; + let total=percentOfPrice+convertToBrazil; + return total; +} /* ======= TESTS - DO NOT MODIFY ===== There are some Tests in this file that will help you work out if your code is working. From c2c540c186c4b8a9d295d377d14b8ed2ea3b72e3 Mon Sep 17 00:00:00 2001 From: zubeda Date: Thu, 18 Jun 2020 05:25:38 +0100 Subject: [PATCH 08/17] extra:2-piping.js os done --- week-1/3-extra/2-piping.js | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/week-1/3-extra/2-piping.js b/week-1/3-extra/2-piping.js index 93c0bf7..08f002b 100644 --- a/week-1/3-extra/2-piping.js +++ b/week-1/3-extra/2-piping.js @@ -16,26 +16,27 @@ the final result to the variable goodCode */ -function add() { +function add(a,b) { + return a+b; } -function multiply() { - +function multiply(a,b) { + return a*b; } -function format() { - +function format(a) { +return `£${a}`; } -const startingValue = 2 +const startingValue = 2; // Why can this code be seen as bad practice? Comment your answer. -let badCode = +let badCode = format((startingValue+10)*2);//no use of variables /* BETTER PRACTICE */ -let goodCode = +let goodCode = badCode;//fisrt put result in variable and the assign to 2nd variable /* ======= TESTS - DO NOT MODIFY ===== There are some Tests in this file that will help you work out if your code is working. @@ -46,17 +47,17 @@ To run these tests type `node 2-piping.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}`) + 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"); \ No newline at end of file From 45f3087a0715b3025db2d632d4e8d1fd711c9d8f Mon Sep 17 00:00:00 2001 From: zubeda Date: Thu, 18 Jun 2020 11:17:05 +0100 Subject: [PATCH 09/17] 3-magic-8-ball.js is done --- week-1/3-extra/3-magic-8-ball.js | 68 +++++++++++++++++++++++++++++--- 1 file changed, 63 insertions(+), 5 deletions(-) diff --git a/week-1/3-extra/3-magic-8-ball.js b/week-1/3-extra/3-magic-8-ball.js index 1bb1089..7a0979e 100644 --- a/week-1/3-extra/3-magic-8-ball.js +++ b/week-1/3-extra/3-magic-8-ball.js @@ -35,7 +35,7 @@ Better not tell you now. Cannot predict now. Concentrate and ask again. -## Very negative +## Negative Don't count on it. My reply is no. My sources say no. @@ -45,17 +45,74 @@ Very doubtful. // This should log "The ball has shaken!" // and return the answer. -function shakeBall() {} - +function shakeBall() { + + logged="The ball has shaken!"; + answers=["Very positive","Positive","Negative","Negative"] +// + //answers[Math.floor(Math.random()*answers.length)] +//console.log(Math.floor(Math.random()*4)); + answer=Math.floor(Math.random()*answers.length) + return answer.toString(); +} +//answers[Math.floor(Math.random()*answers.length)] // The answer should come from shaking the ball -let answer; +//let answer; // When checking the answer, we should tell someone if the answer is // - very positive // - positive // - negative // - very negative -function checkAnswer() {} +function checkAnswer() { + // console.log("ans from main"+answer); + let subAns; + +//let no=shakeBall(); +//console.log("answer again from checkS"+no); +if(answer==0){ + // "); + subAns=["It is certain." + ,"It is decidedly so." + ,"Without a doubt" + ,"Yes - definitely." + ,"You may rely on it."]; + console.log("very positive"); + console.log(subAns[Math.floor(Math.random()*subAns.length)]); + return "very positive"; +} +if(answer==1){ + subAns=["As I see it, yes." + ,"Most likely." + ,"Outlook good." + ,"Yes." + ,"Signs point to yes."]; + console.log("positive"); + console.log(subAns[Math.floor(Math.random()*subAns.length)]); + return "positive"; +} +if(answer==2){ + subAns=["Reply hazy, try again." + ,"Ask again later." + ,"Better not tell you now." + ,"Cannot predict now." + ,"Concentrate and ask again."]; + console.log("negative"); + console.log(subAns[Math.floor(Math.random()*subAns.length)]); + return "negative"; +} +if(answer==3){ + subAns=["Don't count on it." + ,"My reply is no." + ,"My sources say no." + ,"Outlook not so good." + ,"Very doubtful."]; + console.log("very nagative"); + console.log(subAns[Math.floor(Math.random()*subAns.length)]); + return "very negative"; +} + +} /* ======= TESTS - DO NOT MODIFY ===== There are some Tests in this file that will help you work out if your code is working. @@ -89,6 +146,7 @@ function testAll() { `shakeBall logs "The ball has shaken!"`, logged === "The ball has shaken!" ); + test(`shakeBall returns an string answer"`, typeof answer === "string"); test( `checkAnswer returns the level of positivity"`, From 28e5f3d2e5c88474dc61548bf1041a8a2ff7a98e Mon Sep 17 00:00:00 2001 From: zubedauk <63961273+zubedauk@users.noreply.github.com> Date: Thu, 2 Jul 2020 16:46:08 +0100 Subject: [PATCH 10/17] new files updated files --- 2-reading-list.md | 9 ++++++ 3-sorting-algorithm.js | 70 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 2-reading-list.md create mode 100644 3-sorting-algorithm.js diff --git a/2-reading-list.md b/2-reading-list.md new file mode 100644 index 0000000..6bfe2aa --- /dev/null +++ b/2-reading-list.md @@ -0,0 +1,9 @@ +# Reading List + +To challenge yourself even further, you can get ahead for next week's class by reading some of the below documentation: + +- [ ] Arrow functions: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions +- [ ] Anonymous vs named functions: https://blog.scottlogic.com/2011/06/10/javascript-anonymous-functions.html +- [ ] Different ways of creating functions: https://www.w3schools.com/js/js_function_definition.asp +- [ ] Introduction to object literals: http://dyn-web.com/tutorials/object-literal/ +- [ ] Explanation of callbacks: https://codeburst.io/javascript-what-the-heck-is-a-callback-aba4da2deced diff --git a/3-sorting-algorithm.js b/3-sorting-algorithm.js new file mode 100644 index 0000000..3603942 --- /dev/null +++ b/3-sorting-algorithm.js @@ -0,0 +1,70 @@ +/* +At the start of the course, you worked in teams to sort your team members, labelled by +numbers, in ascending or descending order. + +Today, you will be applying the sorting algorithm you used in that exercise in code! + +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 + - 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) {} + +/* ======= TESTS - DO NOT MODIFY ===== */ + +const agesCase1 = [ + "🎹", + 100, + "💩", + 55, + "🥵", + "🙈", + 45, + "🍕", + "Sanyia", + 66, + "James", + 23, + "🎖", + "Ismeal", +]; +const agesCase2 = ["28", 100, 60, 55, "75", "🍕", "Elamin"]; + +function arraysEqual(a, b) { + if (a === b) return true; + if (a == null || b == null) return false; + if (a.length != b.length) return false; + + for (let i = 0; i < a.length; ++i) { + if (a[i] !== b[i]) return false; + } + + return true; +} + +function test(test_name, expr) { + let status; + if (expr) { + status = "PASSED"; + } else { + status = "FAILED"; + } + + console.log(`${test_name}: ${status}`); +} + +test( + "sortAges function works - case 1", + arraysEqual(sortAges(agesCase1), [23, 45, 55, 66, 100]) +); + +test( + "sortAges function works - case 2", + arraysEqual(sortAges(agesCase2), [55, 60, 100]) +); From ac40b4627b981e56df6527727ea6060fb5dd8830 Mon Sep 17 00:00:00 2001 From: zubedauk <63961273+zubedauk@users.noreply.github.com> Date: Thu, 2 Jul 2020 17:07:47 +0100 Subject: [PATCH 11/17] Add files via upload --- week-3/3-extra/3-sorting-algorithm.js | 71 +++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 week-3/3-extra/3-sorting-algorithm.js diff --git a/week-3/3-extra/3-sorting-algorithm.js b/week-3/3-extra/3-sorting-algorithm.js new file mode 100644 index 0000000..895eb9b --- /dev/null +++ b/week-3/3-extra/3-sorting-algorithm.js @@ -0,0 +1,71 @@ +/* +At the start of the course, you worked in teams to sort your team members, labelled by +numbers, in ascending or descending order. + +Today, you will be applying the sorting algorithm you used in that exercise in code! + +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 + - 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) {} + +/* ======= TESTS - DO NOT MODIFY ===== */ + +const agesCase1 = [ + "🎹", + 100, + "💩", + 55, + "🥵", + "🙈", + 45, + "🍕", + "Sanyia", + 66, + "James", + 23, + "🎖", + "Ismeal", +]; +const agesCase2 = ["28", 100, 60, 55, "75", "🍕", "Elamin"]; + +function arraysEqual(a, b) { + if (a === b) return true; + if (a == null || b == null) return false; + if (a.length != b.length) return false; + + for (let i = 0; i < a.length; ++i) { + if (a[i] !== b[i]) return false; + } + + return true; +} + +function test(test_name, expr) { + let status; + if (expr) { + status = "PASSED"; + } else { + status = "FAILED"; + } + + console.log(`${test_name}: ${status}`); +} + +test( + "sortAges function works - case 1", + arraysEqual(sortAges(agesCase1), [23, 45, 55, 66, 100]) +); + +test( + "sortAges function works - case 2", + arraysEqual(sortAges(agesCase2), [55, 60, 100]) +); From 7f26e67cab92a26d5480cb77f06a6091a6ee928c Mon Sep 17 00:00:00 2001 From: zubedauk <63961273+zubedauk@users.noreply.github.com> Date: Thu, 2 Jul 2020 17:11:36 +0100 Subject: [PATCH 12/17] Delete 3-sorting-algorithm.js --- 3-sorting-algorithm.js | 70 ------------------------------------------ 1 file changed, 70 deletions(-) delete mode 100644 3-sorting-algorithm.js diff --git a/3-sorting-algorithm.js b/3-sorting-algorithm.js deleted file mode 100644 index 3603942..0000000 --- a/3-sorting-algorithm.js +++ /dev/null @@ -1,70 +0,0 @@ -/* -At the start of the course, you worked in teams to sort your team members, labelled by -numbers, in ascending or descending order. - -Today, you will be applying the sorting algorithm you used in that exercise in code! - -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 - - 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) {} - -/* ======= TESTS - DO NOT MODIFY ===== */ - -const agesCase1 = [ - "🎹", - 100, - "💩", - 55, - "🥵", - "🙈", - 45, - "🍕", - "Sanyia", - 66, - "James", - 23, - "🎖", - "Ismeal", -]; -const agesCase2 = ["28", 100, 60, 55, "75", "🍕", "Elamin"]; - -function arraysEqual(a, b) { - if (a === b) return true; - if (a == null || b == null) return false; - if (a.length != b.length) return false; - - for (let i = 0; i < a.length; ++i) { - if (a[i] !== b[i]) return false; - } - - return true; -} - -function test(test_name, expr) { - let status; - if (expr) { - status = "PASSED"; - } else { - status = "FAILED"; - } - - console.log(`${test_name}: ${status}`); -} - -test( - "sortAges function works - case 1", - arraysEqual(sortAges(agesCase1), [23, 45, 55, 66, 100]) -); - -test( - "sortAges function works - case 2", - arraysEqual(sortAges(agesCase2), [55, 60, 100]) -); From 47a28717b2fd20edbd7baadbc8938a643811ac67 Mon Sep 17 00:00:00 2001 From: zubedauk <63961273+zubedauk@users.noreply.github.com> Date: Thu, 2 Jul 2020 17:14:09 +0100 Subject: [PATCH 13/17] Delete 2-reading-list.md --- 2-reading-list.md | 9 --------- 1 file changed, 9 deletions(-) delete mode 100644 2-reading-list.md diff --git a/2-reading-list.md b/2-reading-list.md deleted file mode 100644 index 6bfe2aa..0000000 --- a/2-reading-list.md +++ /dev/null @@ -1,9 +0,0 @@ -# Reading List - -To challenge yourself even further, you can get ahead for next week's class by reading some of the below documentation: - -- [ ] Arrow functions: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions -- [ ] Anonymous vs named functions: https://blog.scottlogic.com/2011/06/10/javascript-anonymous-functions.html -- [ ] Different ways of creating functions: https://www.w3schools.com/js/js_function_definition.asp -- [ ] Introduction to object literals: http://dyn-web.com/tutorials/object-literal/ -- [ ] Explanation of callbacks: https://codeburst.io/javascript-what-the-heck-is-a-callback-aba4da2deced From 70c0e354cb2aac2ff2610cf1225fe20ac82bcc52 Mon Sep 17 00:00:00 2001 From: zubeda Date: Thu, 2 Jul 2020 20:35:11 +0100 Subject: [PATCH 14/17] donee --- week-3/1-exercises/A-array-find/exercise.js | 1 + 1 file changed, 1 insertion(+) diff --git a/week-3/1-exercises/A-array-find/exercise.js b/week-3/1-exercises/A-array-find/exercise.js index d7fd51f..7ab6652 100644 --- a/week-3/1-exercises/A-array-find/exercise.js +++ b/week-3/1-exercises/A-array-find/exercise.js @@ -13,3 +13,4 @@ console.log(longNameThatStartsWithA); /* EXPECTED OUTPUT */ // "Alexandra" + From fd086534ddde1a9a24081b991fddd977a821b7cc Mon Sep 17 00:00:00 2001 From: zubeda Date: Thu, 2 Jul 2020 23:01:39 +0100 Subject: [PATCH 15/17] started --- week-3/1-exercises/A-array-find/exercise.js | 1 + 1 file changed, 1 insertion(+) diff --git a/week-3/1-exercises/A-array-find/exercise.js b/week-3/1-exercises/A-array-find/exercise.js index 7ab6652..52b10af 100644 --- a/week-3/1-exercises/A-array-find/exercise.js +++ b/week-3/1-exercises/A-array-find/exercise.js @@ -11,6 +11,7 @@ var longNameThatStartsWithA = findLongNameThatStartsWithA(names); console.log(longNameThatStartsWithA); + /* EXPECTED OUTPUT */ // "Alexandra" From 12cf27e32db1887650797dc6b345bc0e32f2faf5 Mon Sep 17 00:00:00 2001 From: zubeda Date: Thu, 2 Jul 2020 23:38:57 +0100 Subject: [PATCH 16/17] comp --- week-3/1-exercises/A-array-find/exercise.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/week-3/1-exercises/A-array-find/exercise.js b/week-3/1-exercises/A-array-find/exercise.js index 52b10af..a4f3dd9 100644 --- a/week-3/1-exercises/A-array-find/exercise.js +++ b/week-3/1-exercises/A-array-find/exercise.js @@ -4,6 +4,12 @@ */ // write your code here +function findLongNameThatStartsWithA(names){ + let output=names.find(function(name){ + return name.charAt(0)==='A' && name.length>7; + }) + return output; +} var names = ["Rakesh", "Antonio", "Alexandra", "Andronicus", "Annam", "Mikey", "Anastasia", "Karim", "Ahmed"]; @@ -11,7 +17,6 @@ var longNameThatStartsWithA = findLongNameThatStartsWithA(names); console.log(longNameThatStartsWithA); - /* EXPECTED OUTPUT */ // "Alexandra" From 6d4513161b1c7169cee8c8d902f822e1c806369b Mon Sep 17 00:00:00 2001 From: zubeda Date: Sat, 4 Jul 2020 15:30:52 +0100 Subject: [PATCH 17/17] week-3-JavaScript-HomeWork(All++++) --- week-3/1-exercises/A-array-find/exercise.js | 1 + week-3/1-exercises/B-array-some/exercise.js | 12 +++++- week-3/1-exercises/C-array-every/exercise.js | 4 +- week-3/1-exercises/D-array-filter/exercise.js | 7 +++- week-3/1-exercises/E-array-map/exercise.js | 10 ++++- .../1-exercises/F-array-forEach/exercise.js | 16 +++++++- .../1-exercises/G-array-methods/exercise.js | 2 +- .../1-exercises/G-array-methods/exercise2.js | 2 +- .../1-exercises/H-array-methods-2/exercise.js | 4 +- .../H-array-methods-2/exercise2.js | 5 ++- .../H-array-methods-2/exercise3.js | 2 +- week-3/2-mandatory/1-oxygen-levels.js | 7 +++- week-3/2-mandatory/2-bush-berries.js | 12 +++++- week-3/2-mandatory/3-space-colonies.js | 7 +++- week-3/2-mandatory/4-eligible-students.js | 12 +++++- week-3/2-mandatory/5-journey-planner.js | 15 ++++++- week-3/2-mandatory/6-lane-names.js | 7 +++- week-3/2-mandatory/7-password-validator.js | 25 +++++++++++- week-3/3-extra/3-sorting-algorithm.js | 13 ++++++- week-3/3-extra/card-validator.js | 39 +++++++++++++++++++ 20 files changed, 176 insertions(+), 26 deletions(-) create mode 100644 week-3/3-extra/card-validator.js diff --git a/week-3/1-exercises/A-array-find/exercise.js b/week-3/1-exercises/A-array-find/exercise.js index a4f3dd9..da18d4d 100644 --- a/week-3/1-exercises/A-array-find/exercise.js +++ b/week-3/1-exercises/A-array-find/exercise.js @@ -3,6 +3,7 @@ Using .find(), we'd like to find the first name which starts with A and is longer than 7 letters. */ + // write your code here function findLongNameThatStartsWithA(names){ let output=names.find(function(name){ diff --git a/week-3/1-exercises/B-array-some/exercise.js b/week-3/1-exercises/B-array-some/exercise.js index 965c052..8f51db6 100644 --- a/week-3/1-exercises/B-array-some/exercise.js +++ b/week-3/1-exercises/B-array-some/exercise.js @@ -6,12 +6,21 @@ - Do not edit any of the existing code */ -var pairsByIndex = [[0, 3], [1, 2], [2, 1], null, [3, 0]]; +var pairsByIndex = [[0, 3], [1, 2], [2, 1], null, [3, 0]]; +let test=pairsByIndex.some(function(value){ + return value===null; +}) +if(test){ + console.log("array contain null value"); + process.exit(1) +} +else{ // If there is a null value in the array exit the program with the error code // 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"]; @@ -22,3 +31,4 @@ var pairs = pairsByIndex.map(function(indexes) { }); console.log(pairs); +} \ No newline at end of file diff --git a/week-3/1-exercises/C-array-every/exercise.js b/week-3/1-exercises/C-array-every/exercise.js index b515e94..1cd95e2 100644 --- a/week-3/1-exercises/C-array-every/exercise.js +++ b/week-3/1-exercises/C-array-every/exercise.js @@ -5,7 +5,9 @@ var students = ["Omar", "Austine", "Dany", "Swathi", "Lesley", "Rukmini"]; var group = ["Austine", "Dany", "Swathi", "Daniel"]; -var groupIsOnlyStudents; // complete this statement +var groupIsOnlyStudents=group.every(function(name){ + return students.includes(name); +}); // complete this statement if (groupIsOnlyStudents) { console.log("The group contains only students"); diff --git a/week-3/1-exercises/D-array-filter/exercise.js b/week-3/1-exercises/D-array-filter/exercise.js index 6e32cc6..936c295 100644 --- a/week-3/1-exercises/D-array-filter/exercise.js +++ b/week-3/1-exercises/D-array-filter/exercise.js @@ -1,6 +1,7 @@ /* You are given a program that logs pairings between mentors and students - It fails because the array `pairsById` can contain different values that break the program + It fails because the array `pairsById` can contain different values that + break the program It is decided that array items which are not pairs should be filtered out - Finish the statement on line 11 to produce an array with valid content - Do not edit any of the existing code @@ -8,7 +9,9 @@ var pairsByIndexRaw = [[0, 3], [1, 2], [2, 1], null, [1], false, "whoops"]; -var pairsByIndex; // Complete this statement +var pairsByIndex=pairsByIndexRaw.filter(function(value){ + return Array.isArray(value) && value.length>1; +}); // Complete this statement var students = ["Islam", "Lesley", "Harun", "Rukmini"]; var mentors = ["Daniel", "Irina", "Mozafar", "Luke"]; diff --git a/week-3/1-exercises/E-array-map/exercise.js b/week-3/1-exercises/E-array-map/exercise.js index 2835e92..379381e 100644 --- a/week-3/1-exercises/E-array-map/exercise.js +++ b/week-3/1-exercises/E-array-map/exercise.js @@ -2,4 +2,12 @@ // Write multiple solutions using different syntax (as shown in the README) var numbers = [0.1, 0.2, 0.3, 0.4, 0.5]; - +var brandNewArray; +brandNewArray=numbers.map(function(num){ + return num*100; +}) +brandNewArray=numbers.map(num=>{ + return num*100; +}) +brandNewArray=numbers.map(num=>num*100); +console.log(brandNewArray); diff --git a/week-3/1-exercises/F-array-forEach/exercise.js b/week-3/1-exercises/F-array-forEach/exercise.js index e83e2df..05d00b6 100644 --- a/week-3/1-exercises/F-array-forEach/exercise.js +++ b/week-3/1-exercises/F-array-forEach/exercise.js @@ -8,7 +8,21 @@ */ var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]; - +var output=arr.forEach(function(num,index){ + if(num%3===0 && num%5===0){ + console.log("FizzBuzz"); + } + else if(num%5===0){ + console.log("Buzz"); + } + else if(num%3===0){ + console.log("Fizz"); + } + else{ + console.log(num); + } +}) +console.log(output); /* EXPECTED OUTPUT */ /* diff --git a/week-3/1-exercises/G-array-methods/exercise.js b/week-3/1-exercises/G-array-methods/exercise.js index 44e9c80..5dc3c88 100644 --- a/week-3/1-exercises/G-array-methods/exercise.js +++ b/week-3/1-exercises/G-array-methods/exercise.js @@ -4,7 +4,7 @@ */ var numbers = [3, 2, 1]; -var sortedNumbers; // complete this statement +var sortedNumbers=numbers.sort(); // complete this statement /* DO NOT EDIT BELOW THIS LINE diff --git a/week-3/1-exercises/G-array-methods/exercise2.js b/week-3/1-exercises/G-array-methods/exercise2.js index 3dd24a1..a39171f 100644 --- a/week-3/1-exercises/G-array-methods/exercise2.js +++ b/week-3/1-exercises/G-array-methods/exercise2.js @@ -7,7 +7,7 @@ var mentors = ["Daniel", "Irina", "Rares"]; var students = ["Rukmini", "Abdul", "Austine", "Swathi"]; -var everyone; // complete this statement +var everyone=mentors.concat(students);// complete this statement /* DO NOT EDIT BELOW THIS LINE diff --git a/week-3/1-exercises/H-array-methods-2/exercise.js b/week-3/1-exercises/H-array-methods-2/exercise.js index d36303b..286f892 100644 --- a/week-3/1-exercises/H-array-methods-2/exercise.js +++ b/week-3/1-exercises/H-array-methods-2/exercise.js @@ -15,8 +15,8 @@ var everyone = [ "Swathi" ]; -var firstFive; // complete this statement -var lastFive; // complete this statement +var firstFive=everyone.slice(0,5); // complete this statement +var lastFive=everyone.slice(-5); // complete this statement /* DO NOT EDIT BELOW THIS LINE diff --git a/week-3/1-exercises/H-array-methods-2/exercise2.js b/week-3/1-exercises/H-array-methods-2/exercise2.js index b7be576..e347306 100644 --- a/week-3/1-exercises/H-array-methods-2/exercise2.js +++ b/week-3/1-exercises/H-array-methods-2/exercise2.js @@ -6,8 +6,11 @@ For example, capitailise("hello") should return "Hello" Tip: use the string method .split() and the array method .join() */ +//return name.split("")[0].toUpperCase() + name.slice(1); +function capitalise(str) { + return str.split("")[0].toUpperCase().concat(str.slice(1)); -function capitalise(str) {} +} /* DO NOT EDIT BELOW THIS LINE diff --git a/week-3/1-exercises/H-array-methods-2/exercise3.js b/week-3/1-exercises/H-array-methods-2/exercise3.js index 82e9dd8..3bb1abd 100644 --- a/week-3/1-exercises/H-array-methods-2/exercise3.js +++ b/week-3/1-exercises/H-array-methods-2/exercise3.js @@ -7,7 +7,7 @@ var ukNations = ["Scotland", "Wales", "England", "Northern Ireland"]; function isInUK(country) { - return; // complete this statement + return ukNations.some(name=>name.includes(country)); // complete this statement } /* diff --git a/week-3/2-mandatory/1-oxygen-levels.js b/week-3/2-mandatory/1-oxygen-levels.js index f9d745f..49f9db4 100644 --- a/week-3/2-mandatory/1-oxygen-levels.js +++ b/week-3/2-mandatory/1-oxygen-levels.js @@ -9,8 +9,11 @@ To be safe to land on, a planet needs to have an Oxygen level between 19.5% and Write a function that finds the first safe oxygen level in the array - Oxygen between 19.5% and 23.5% */ -function safeLevels() { - +function safeLevels(arr) { + var findLevel=arr.find(function(level){ + return parseFloat(level)>19.5 && parseFloat(level)<23.5; + }) + return findLevel; } /* ======= TESTS - DO NOT MODIFY ===== */ diff --git a/week-3/2-mandatory/2-bush-berries.js b/week-3/2-mandatory/2-bush-berries.js index aca45ad..8903f6e 100644 --- a/week-3/2-mandatory/2-bush-berries.js +++ b/week-3/2-mandatory/2-bush-berries.js @@ -10,8 +10,16 @@ Use the tests to confirm which message to return */ -function bushChecker() { - +function bushChecker(arr) { + if(arr.every(function(barries){ + return barries==="pink"; + })){ + return "Bush is safe to eat from"; + } + else{ + 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 239eddd..54e79a7 100644 --- a/week-3/2-mandatory/3-space-colonies.js +++ b/week-3/2-mandatory/3-space-colonies.js @@ -8,8 +8,11 @@ NOTE: don't include any element that is not a "family". */ -function colonisers() { - +function colonisers(arr) { + let output=arr.filter(function(names){ + return names.charAt(0)==='A' && names.includes("family"); + }) + return output; } /* ======= TESTS - DO NOT MODIFY ===== */ diff --git a/week-3/2-mandatory/4-eligible-students.js b/week-3/2-mandatory/4-eligible-students.js index d8fe052..7d71aaa 100644 --- a/week-3/2-mandatory/4-eligible-students.js +++ b/week-3/2-mandatory/4-eligible-students.js @@ -7,8 +7,16 @@ - Returns an array containing only the names of the who have attended AT LEAST 8 classes */ -function eligibleStudents() { - +function eligibleStudents(arr) { + var output=arr.filter(function(record){ + + return parseFloat(record[1])>=8; + }).map(function(record){ + return record[0]; + }) + + //console.log(final); + return output; } /* ======= TESTS - DO NOT MODIFY ===== */ diff --git a/week-3/2-mandatory/5-journey-planner.js b/week-3/2-mandatory/5-journey-planner.js index 816637d..27ce5be 100644 --- a/week-3/2-mandatory/5-journey-planner.js +++ b/week-3/2-mandatory/5-journey-planner.js @@ -7,7 +7,19 @@ NOTE: only the names should be returned, not the means of transport. */ -function journeyPlanner() { +function journeyPlanner(arr,transport) { + let output=arr.filter(function(rout){ + if(rout.includes(transport)){ + //console.log(rout[0]) + return rout; + //return rout; + }; + }).map(function(rout){ + return rout[0]; + }) + + + return output; } /* ======= TESTS - DO NOT MODIFY ===== */ @@ -20,6 +32,7 @@ const londonLocations = [ ] const util = require('util'); +const { runInContext } = require('vm'); function test(test_name, actual, expected) { let status; diff --git a/week-3/2-mandatory/6-lane-names.js b/week-3/2-mandatory/6-lane-names.js index ef4e1c5..4cb9e67 100644 --- a/week-3/2-mandatory/6-lane-names.js +++ b/week-3/2-mandatory/6-lane-names.js @@ -4,8 +4,11 @@ Write a function that will return all street names which contain 'Lane' in their name. */ -function getLanes() { - +function getLanes(arr) { + let output=arr.filter(function(name){ + return name.includes("Lane"); + }) + return output; } /* ======= TESTS - DO NOT MODIFY ===== */ diff --git a/week-3/2-mandatory/7-password-validator.js b/week-3/2-mandatory/7-password-validator.js index 8f9e597..9650fc8 100644 --- a/week-3/2-mandatory/7-password-validator.js +++ b/week-3/2-mandatory/7-password-validator.js @@ -23,8 +23,29 @@ PasswordValidationResult= [false, false, false, false, true] */ function validatePasswords(passwords) { - -} + //exclude the duplicate value + for(let i=0;i16) + { + return true; + } + else{ + isValid=false; + } + + +} +//main program send card number to isValidateCard(cardNumber) function check the number +let cardNumber="6666666666666661"; +var isValid=isValidateCard(cardNumber); +if(Boolean(isValid)){ + console.log("credit card number is valid"); +} +else{ + console.log("credit card number is not valid"); +} \ No newline at end of file