From de63b19640cc3f9c4fc908d54802ccb765f1a109 Mon Sep 17 00:00:00 2001 From: NeginDn Date: Fri, 22 Jan 2021 12:05:24 +0000 Subject: [PATCH 1/3] Exercises --- .DS_Store | Bin 0 -> 6148 bytes exercises/.DS_Store | Bin 0 -> 10244 bytes exercises/B-hello-world/exercise.js | 2 ++ exercises/C-variables/exercise.js | 6 +++--- exercises/D-strings/README.md | 1 + exercises/D-strings/exercise.js | 3 ++- exercises/E-strings-concatenation/exercise.js | 3 +++ exercises/F-strings-methods/exercise.js | 4 +++- exercises/F-strings-methods/exercise2.js | 11 +++++++++-- exercises/G-numbers/exercise.js | 6 ++++++ exercises/I-floats/exercise.js | 8 ++++++++ exercises/J-functions/exercise.js | 7 ++++++- exercises/J-functions/exercise2.js | 7 ++++++- exercises/K-functions-parameters/exercise.js | 9 +++++++-- exercises/K-functions-parameters/exercise2.js | 9 ++++++++- exercises/K-functions-parameters/exercise3.js | 9 ++++++++- exercises/K-functions-parameters/exercise4.js | 11 +++++++++-- exercises/K-functions-parameters/exercise5.js | 13 +++++++++++-- exercises/L-functions-nested/.DS_Store | Bin 0 -> 6148 bytes exercises/L-functions-nested/exercise.js | 15 +++++++++++++++ 20 files changed, 107 insertions(+), 17 deletions(-) create mode 100644 .DS_Store create mode 100644 exercises/.DS_Store create mode 100644 exercises/L-functions-nested/.DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..189db01b621efa209ac8cb4e5a22f85c2e5d84ee GIT binary patch literal 6148 zcmeHK%Wl&^6ur}?U>hMKgw$@3ykVDANmDgqf#iln5Q##C16=@W?K+~CT)T=LLJ2|H z^98Wr7x)gofNx<1XC9!~F*{UMXs&eUT+hrIdycPXJVeAg6v1D^UtC%%^HpGY-P2wcIB#JScY}odgY!Z6F2j+aoX`lFZk8Im!0@39wbTh zC-(g3;c#+Ty>&l{GcSyXBS8*>A-cRg2;(4`bdqr#q+%RbHW-F!n1|Jk>2zzWU9($_ zomtJEw%d)Gz1`ZG%}itcPV-*>==A*E^!@C^CovgfSiFSYQ1}}@BPbE)jXR2?Bz}!n z&Ri4nWsuM7M>*NPqIFR=iyqKZh}oq+Jx07qrxfHl>~?{3lOEC&I-oiYfOW8Xi0Y{A z(IeU~9phtRjA~&Fm!46F_V5&gQvQzu-^6oz6jOjQqXaWO&p)+DkT1CeSz=tW1ZlRm zksz(R{~$q@rdmi46ED3dUi%)f$)<-r#G1Hm!hGKr67Q0AC+$I7dg} zT%uSyP>3S{u!3q~i1`l#=hzAzg>#8$fiX!1N-9%F3?}KQw^ct!;asAm6H|u|rtZwt z35AKfV|-h5C+0}hrB*;IkXK+;URL@3-~0RdKTpzES^=%Vf29Dcblq+TQ&M~D(&YGF uYr~J=+<3paL_tBJwqp_St#|`23~e?KfR4hsMAX3akARRt7g~V}Rp1xyqWQW2 literal 0 HcmV?d00001 diff --git a/exercises/.DS_Store b/exercises/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..d0bf53646a547a74a15283a0c482076025731b5f GIT binary patch literal 10244 zcmeI1&u`N(6vv<0fOKUr5Mo@AvI7!_fx30t!~v=6Hqd|rQV|>gZOIzeNL^Aj=_)8i zz4I5qfq#L&gTH{kg%f=JgDG>8snsSiMRsLB$MJLZK923Y7b0TyUUP}aCL#-&%egBk zG7`Vfb1Gd>Eentg`b07Hs6+S3r)H|RX)pu~0YktLFa!*N^FRP+HcwVrN>dsFhJYb( zM1b!PHZqqrB}Y<cpfvG4;<(c_>W$JM?VPomfpuQyKz>K$^e;n#!~epFJY)nE&o=x5GWR9lGej z7u7oQgFhmnmaFCVqmI)0>2}(F6jv(0*oCR-iAvAt zFPymLs`|??Y#-Gf_m%JUcjj(xghA~1f!7tve$zvjx3B%68TRX8FK9+$oQAw%StYBq zGk1G1SYBRRw5yfX;i5fQTdOSEE7jHEuw>2OU3#>=d+_1o;M4H)S78t_wYShUd3{uV z%QyG1(GA*Ru#X;GdzR`z*#gQoej)08lwH)D8qOc+oy2*9W>JxzV6uj_OdCLXNDff? zC|v;cC_0Xm-O-TdXcZM_j=37j5^ajb9t)HK?WZt)(J*FcoHK+=)fFuA>cdkn@(fco zeDk!W{AZqW0b$p|n3k(dVEd4Mm*t|kt!vBo%O@XyRM8_ReN zIv!$^rX&KJ$N#tTzyBLhhJYbZU;=D&@&6H+9XqyqW?>iO|4$m$K0W%srIep2 literal 0 HcmV?d00001 diff --git a/exercises/B-hello-world/exercise.js b/exercises/B-hello-world/exercise.js index b179ee953..29055b8ee 100644 --- a/exercises/B-hello-world/exercise.js +++ b/exercises/B-hello-world/exercise.js @@ -1 +1,3 @@ console.log("Hello world"); +console.log("Hello World. I just started learning JavaScript!"); +console.log(123); \ No newline at end of file diff --git a/exercises/C-variables/exercise.js b/exercises/C-variables/exercise.js index a6bbb9786..7185a9124 100644 --- a/exercises/C-variables/exercise.js +++ b/exercises/C-variables/exercise.js @@ -1,3 +1,3 @@ -// Start by creating a variable `greeting` - -console.log(greeting); +//* Print your `greeting` to the console 3 times +let greeting = "Welcome to coding world"; +for (let i = 0; i < 3; i++) console.log(greeting); diff --git a/exercises/D-strings/README.md b/exercises/D-strings/README.md index 1516f536e..28327adcf 100644 --- a/exercises/D-strings/README.md +++ b/exercises/D-strings/README.md @@ -21,6 +21,7 @@ console.log(messageType); // logs 'string' * Write a program that logs a message and its type + ## Expected result ``` diff --git a/exercises/D-strings/exercise.js b/exercises/D-strings/exercise.js index 2cffa6a81..0974d29ed 100644 --- a/exercises/D-strings/exercise.js +++ b/exercises/D-strings/exercise.js @@ -1,3 +1,4 @@ // Start by creating a variable `message` - +let message = "This variable type is string"; console.log(message); +console.log(typeof message); diff --git a/exercises/E-strings-concatenation/exercise.js b/exercises/E-strings-concatenation/exercise.js index 2cffa6a81..68332fb27 100644 --- a/exercises/E-strings-concatenation/exercise.js +++ b/exercises/E-strings-concatenation/exercise.js @@ -1,3 +1,6 @@ // Start by creating a variable `message` +let myName = "Negin"; +let greeting = "Hello, My name is "; +let message = greeting + " " + myName; console.log(message); diff --git a/exercises/F-strings-methods/exercise.js b/exercises/F-strings-methods/exercise.js index 2cffa6a81..cd4a6281b 100644 --- a/exercises/F-strings-methods/exercise.js +++ b/exercises/F-strings-methods/exercise.js @@ -1,3 +1,5 @@ // Start by creating a variable `message` - +let myName = "Negin"; +let lengthName = myName.length; +let message = "Hello my name is " + myName + " and my name is " + lengthName + " character long"; console.log(message); diff --git a/exercises/F-strings-methods/exercise2.js b/exercises/F-strings-methods/exercise2.js index b4b46943d..d965bd042 100644 --- a/exercises/F-strings-methods/exercise2.js +++ b/exercises/F-strings-methods/exercise2.js @@ -1,3 +1,10 @@ -const name = " Daniel "; - +const name = " Negin "; +let trimName = name.trim(); +let lengthName = trimName.length; +let message = + "Hello my name is " + + trimName + + " and my name is " + + lengthName + + " character long"; console.log(message); diff --git a/exercises/G-numbers/exercise.js b/exercises/G-numbers/exercise.js index 49e7bc00b..d7bbc28a5 100644 --- a/exercises/G-numbers/exercise.js +++ b/exercises/G-numbers/exercise.js @@ -1 +1,7 @@ // Start by creating a variables `numberOfStudents` and `numberOfMentors` +let numberOfStudents = 15; +let numberOfmentors = 8; +let totalParticipants = numberOfStudents + numberOfmentors; +console.log("number of students: " + numberOfStudents); +console.log("number of mentors: " + numberOfmentors); +console.log("Total number of students and mentors : " + totalParticipants); diff --git a/exercises/I-floats/exercise.js b/exercises/I-floats/exercise.js index a5bbcd852..0d1739438 100644 --- a/exercises/I-floats/exercise.js +++ b/exercises/I-floats/exercise.js @@ -1,2 +1,10 @@ var numberOfStudents = 15; var numberOfMentors = 8; +let totalParticipants = numberOfStudents + numberOfMentors; + +let studentPercentage = Math.round((numberOfStudents / totalParticipants) * 100); +let mentorPercentage = Math.round((numberOfMentors / totalParticipants) * 100); + + +console.log("Percentage students: " + studentPercentage + "%"); +console.log("Percentage mentors: " + mentorPercentage+ "%"); \ No newline at end of file diff --git a/exercises/J-functions/exercise.js b/exercises/J-functions/exercise.js index 0ae5850e5..103c8a255 100644 --- a/exercises/J-functions/exercise.js +++ b/exercises/J-functions/exercise.js @@ -1,7 +1,12 @@ function halve(number) { - // complete the function here + return number / 2; } var result = halve(12); +console.log(result); + +result = halve(1789); +console.log(result); +result = halve(20); console.log(result); diff --git a/exercises/J-functions/exercise2.js b/exercises/J-functions/exercise2.js index 82ef5e780..08ca5f7b5 100644 --- a/exercises/J-functions/exercise2.js +++ b/exercises/J-functions/exercise2.js @@ -1,7 +1,12 @@ function triple(number) { - // complete function here + return number * 3; } var result = triple(12); +console.log(result); + +var result = triple(100); +console.log(result); +var result = triple(34.67); console.log(result); diff --git a/exercises/K-functions-parameters/exercise.js b/exercises/K-functions-parameters/exercise.js index 8d5db5e69..447560c16 100644 --- a/exercises/K-functions-parameters/exercise.js +++ b/exercises/K-functions-parameters/exercise.js @@ -1,9 +1,14 @@ // Complete the function so that it takes input parameters -function multiply() { - // Calculate the result of the function and return it +function multiply(number1, number2) { + return number1 * number2; } // Assign the result of calling the function the variable `result` var result = multiply(3, 4); +console.log(result); + +var result = multiply(5, 34); +console.log(result); +var result = multiply(0, 4); console.log(result); diff --git a/exercises/K-functions-parameters/exercise2.js b/exercises/K-functions-parameters/exercise2.js index db7a8904b..2845a2829 100644 --- a/exercises/K-functions-parameters/exercise2.js +++ b/exercises/K-functions-parameters/exercise2.js @@ -1,5 +1,12 @@ -// Declare your function first +function divide(number1, number2) { + return number1 / number2; +} var result = divide(3, 4); +console.log(result); +var result = divide(1000, 10); console.log(result); + +var result = divide(45, 8); +console.log(result); \ No newline at end of file diff --git a/exercises/K-functions-parameters/exercise3.js b/exercises/K-functions-parameters/exercise3.js index 537e9f4ec..3979171ab 100644 --- a/exercises/K-functions-parameters/exercise3.js +++ b/exercises/K-functions-parameters/exercise3.js @@ -1,5 +1,12 @@ -// Write your function here +function createGreeting(personName) { + return "Hello, my name is " + personName; +} var greeting = createGreeting("Daniel"); +console.log(greeting); + +var greeting = createGreeting("Negin"); +console.log(greeting); +var greeting = createGreeting("John"); console.log(greeting); diff --git a/exercises/K-functions-parameters/exercise4.js b/exercises/K-functions-parameters/exercise4.js index 7ab44589e..3103b4e9d 100644 --- a/exercises/K-functions-parameters/exercise4.js +++ b/exercises/K-functions-parameters/exercise4.js @@ -1,5 +1,12 @@ -// Declare your function first +function sumNumbers(number1, number2) { + return number1 + number2; +} -// Call the function and assign to a variable `sum` +let sum = sumNumbers(10, 15); +console.log(sum); + +sum = sumNumbers(1, 2); +console.log(sum); +sum = sumNumbers(178, 195); console.log(sum); diff --git a/exercises/K-functions-parameters/exercise5.js b/exercises/K-functions-parameters/exercise5.js index 7c5bcd605..48ae85281 100644 --- a/exercises/K-functions-parameters/exercise5.js +++ b/exercises/K-functions-parameters/exercise5.js @@ -1,5 +1,14 @@ -// Declare your function here +function createLongGreeting(personName, personAge) { + return ( + "Hello, my name is " + personName + " and I'm " + personAge + " years old" + ); +} -const greeting = createLongGreeting("Daniel", 30); +let greeting = createLongGreeting("Daniel", 30); +console.log(greeting); + greeting = createLongGreeting("Negin", 32); console.log(greeting); + + greeting = createLongGreeting("John", 110); +console.log(greeting); \ No newline at end of file diff --git a/exercises/L-functions-nested/.DS_Store b/exercises/L-functions-nested/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..523e527902f17903dea3de6057afbd68093155c6 GIT binary patch literal 6148 zcmeHKyH3ME5S)b+K~SWmyf3f>UvNZDK|upQfRa#vf+7(`O6iWz;S*u@0g7X2DPULH zox8mqpFM^54uDLz%L`xvU`$uUtA?TJy86J5BBLnwj0GOC!2>SQ4646RDEEwv9sLFS z{3mR#SL?-mwVty^U+{|Fyqj?ZoZuESW?S448$4rqz<4`g7%f98kP4&%sX!|5uN7d= zRvVu>W=sWAfmGm20sTJ|x?&CN9PQV^pvQMzA1SJFYv26m24huF@1PV6jkLlN7Z`C{de>X)_+G*B1Ic{nJ=$ Date: Fri, 22 Jan 2021 14:00:40 +0000 Subject: [PATCH 2/3] Mandetory --- .DS_Store | Bin 6148 -> 6148 bytes exercises/L-functions-nested/.DS_Store | Bin 6148 -> 6148 bytes mandatory/1-syntax-errors.js | 40 ++++++++++++++----------- mandatory/2-logic-error.js | 7 ++--- mandatory/3-function-output.js | 8 ++--- mandatory/4-tax.js | 9 ++++-- 6 files changed, 37 insertions(+), 27 deletions(-) diff --git a/.DS_Store b/.DS_Store index 189db01b621efa209ac8cb4e5a22f85c2e5d84ee..ec8ac7e6b45169e3ab61ff470c192314886ab413 100644 GIT binary patch delta 16 XcmZoMXffEp!an&ii}z-K_N@W{G35of delta 21 ccmZoMXffEp!p>o6Y@(xJY;3uihy8~D06eM%eE Date: Fri, 22 Jan 2021 19:35:36 +0000 Subject: [PATCH 3/3] Extra --- extra/1-currency-conversion.js | 11 +++++-- extra/2-piping.js | 54 ++++++++++++++++++---------------- 2 files changed, 37 insertions(+), 28 deletions(-) diff --git a/extra/1-currency-conversion.js b/extra/1-currency-conversion.js index 70a2fe863..3529f2848 100644 --- a/extra/1-currency-conversion.js +++ b/extra/1-currency-conversion.js @@ -5,8 +5,10 @@ Write a function that converts a price to USD (exchange rate is 1.4 $ to £) */ -function convertToUSD() {} - +function convertToUSD(poundPrice) { + let dollarPrice = poundPrice * 1.4; + return dollarPrice; +} /* CURRENCY FORMATTING =================== @@ -15,7 +17,10 @@ function convertToUSD() {} They have also decided that they should add a 1% fee to all foreign transactions, which means you only convert 99% of the £ to BRL. */ -function convertToBRL() {} +function convertToBRL(poundPrice) { +let realPrice = poundPrice * 5.7 * 0.99; +return realPrice; +} /* ======= TESTS - DO NOT MODIFY ===== There are some Tests in this file that will help you work out if your code is working. diff --git a/extra/2-piping.js b/extra/2-piping.js index 067dd0f5b..dbdb53976 100644 --- a/extra/2-piping.js +++ b/extra/2-piping.js @@ -13,29 +13,31 @@ - format it 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 + the final result to the variable goodCode; */ -function add() { - +function add(number1, number2) { + return number1 + number2; } -function multiply() { - +function multiply(number1, number2) { + return number1 * number2; } -function format() { - +function format(number) { + return "£" + number.toString(); } -const startingValue = 2 +const startingValue = 2; // Why can this code be seen as bad practice? Comment your answer. -let badCode = +let badCode = format(multiply(add(startingValue, 10), 2)); /* BETTER PRACTICE */ -let goodCode = +let sum = add(startingValue, 10); +let multiplies = multiply(sum, 2); +let goodCode = format(multiplies); /* ======= TESTS - DO NOT MODIFY ===== There are some Tests in this file that will help you work out if your code is working. @@ -43,22 +45,24 @@ There are some Tests in this file that will help you work out if your code is wo To run these tests type `node 2-piping.js` into your terminal */ -const util = require('util'); +const util = require("util"); function test(test_name, actual, expected) { - let status; - if (actual === expected) { - status = "PASSED"; - } else { - status = `FAILED: expected: ${util.inspect(expected)} but your code returned: ${util.inspect(actual)}`; - } - - console.log(`${test_name}: ${status}`); + let status; + if (actual === expected) { + status = "PASSED"; + } else { + status = `FAILED: expected: ${util.inspect( + expected + )} but your code returned: ${util.inspect(actual)}`; + } + + 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), 7.4) -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") +test("add function - case 1 works", add(1, 3), 4); +test("add function - case 2 works", add(2.4, 5), 7.4); +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");