From c070507d212bee9a5f9d2d04792a0dc2ee12592d Mon Sep 17 00:00:00 2001 From: Meysam Arshadi Date: Wed, 23 Nov 2022 18:04:41 +0000 Subject: [PATCH 1/2] Final Submition --- .DS_Store | Bin 0 -> 8196 bytes exercises/.DS_Store | Bin 0 -> 10244 bytes exercises/B-hello-world/exercise.js | 6 +++++- exercises/C-variables/exercise.js | 4 +++- exercises/D-strings/exercise.js | 4 +++- exercises/E-strings-concatenation/exercise.js | 4 +++- exercises/F-strings-methods/exercise.js | 5 ++++- exercises/F-strings-methods/exercise2.js | 6 ++++-- exercises/G-numbers/exercise.js | 12 +++++++++++ exercises/I-floats/exercise.js | 10 +++++++-- exercises/J-functions/exercise.js | 4 ++-- exercises/J-functions/exercise2.js | 2 +- exercises/K-functions-parameters/exercise.js | 15 +++++++------ exercises/K-functions-parameters/exercise2.js | 3 +++ exercises/K-functions-parameters/exercise3.js | 3 +++ exercises/K-functions-parameters/exercise4.js | 6 ++++-- exercises/K-functions-parameters/exercise5.js | 13 +++++++++++- exercises/L-functions-nested/exercise.js | 7 ++++++ mandatory/1-syntax-errors.js | 20 ++++++++++++------ mandatory/2-logic-error.js | 14 ++++++++---- mandatory/3-function-output.js | 8 +++++++ mandatory/4-tax.js | 20 +++++++++++++++--- 22 files changed, 130 insertions(+), 36 deletions(-) create mode 100644 .DS_Store create mode 100644 exercises/.DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..8c51db834d6c2c876ee878bf7b8cc35dce8109e2 GIT binary patch literal 8196 zcmeHMzmF0@6n?{jx8yXT;39=Fo7fqm9HNHUtcaC`iEFe_gS&vRxn+mIA{s(MYySgV3lrb`fSZMd*m!4hGs(<1%zJO%n{S3$-U0xmGH7f8b}h%m=- zQ|eg~Cjx~z5Se@s>6yq3g>dgUzsc2sSORsc8PE(YGQe{8B%Fg5co0VN_eA}wD(lc{ z)%B^1W5&Dpzkj}Y^?6R-SSjzem3ITFJ)8#Cr+%Rg18^hW!8pCBp~m2qc5ccT=H}_p z{YaK;MdAVe$|4O-c!ISDb!4NDy}mo_cjc--xn1AuhlRp7l2}Woj;$Mpv0*&0+jMA$ zPB`dSoZdb5={BXlJMBB}9j`g8WwO_35ISDa>~RCH(L|N|cfFuNhZQ;q8hvhS3xSbN zr)!zqXmqhu%A4iO<#FB|m5YVES-Nm(JWd;%XU<=_RonJE0e#M>#0yVejBrAHp0zKq z7qhY`+truxS}NlwizV__?0U?6D(kB?Bg~VpEYO(w9^1XZr$Gy)Y-K6FHzDqg6OBAq zj7rsrACcYZ8By%jNaHmk5kdhSV1ylTAb-793ck&09*=t8vp-VC%6{3f}neG zDY$a2JO6?UH{vhwyboSpl9x;q5EO2Pyql)yzMOONUNZNUh`io;OCPFF1gAw%GiRirlgT>;OAp z91zck0K14?9XBe9 z4lF9rHt$!@4DZT}l>2rWS^fbCRWUm4A4iKgngS&rbRD`4b*D6hx;ferG)^eVsr*=u zv=yEuMqx?6%Q#hcKH8z|0)=uUok+eBO$%HfgR28&^ZfPP@N^hq(XZ?dBK({wJuYm2YdC{xI5V_K_-X+DF!h z0c6k>dRXE^1nr4*Aoq@Jhuh}ax>vuA?yatAkHxyVS)GB<$s0Ss4zL6406V}AG;fxGG=1FFaigM42S%nN%5+4vn*Y~+3^1#jT>n$zsIN-u^z3?Ai|c>CY3**; T!%h3h-nW66P+QgF>Ms5PsoRvI literal 0 HcmV?d00001 diff --git a/exercises/B-hello-world/exercise.js b/exercises/B-hello-world/exercise.js index b179ee953..2712f5dad 100644 --- a/exercises/B-hello-world/exercise.js +++ b/exercises/B-hello-world/exercise.js @@ -1 +1,5 @@ -console.log("Hello world"); +console.log("Hello world. This is a Test"); +console.log("Hjkl;fe c"); +console.log("Hellodsxzwsaz`is a Test"); +console.log("Hello world. Tlllllllllllllllllll"); +console.log(8); diff --git a/exercises/C-variables/exercise.js b/exercises/C-variables/exercise.js index a6bbb9786..8a64cdb27 100644 --- a/exercises/C-variables/exercise.js +++ b/exercises/C-variables/exercise.js @@ -1,3 +1,5 @@ // Start by creating a variable `greeting` - +let greeting = "Hello World!"; +console.log(greeting); +console.log(greeting); console.log(greeting); diff --git a/exercises/D-strings/exercise.js b/exercises/D-strings/exercise.js index 2cffa6a81..9633e4ced 100644 --- a/exercises/D-strings/exercise.js +++ b/exercises/D-strings/exercise.js @@ -1,3 +1,5 @@ // Start by creating a variable `message` - +let message = "This is my message"; +let messageType = typeof message; console.log(message); +console.log(messageType); diff --git a/exercises/E-strings-concatenation/exercise.js b/exercises/E-strings-concatenation/exercise.js index 2cffa6a81..e85a443a7 100644 --- a/exercises/E-strings-concatenation/exercise.js +++ b/exercises/E-strings-concatenation/exercise.js @@ -1,3 +1,5 @@ // Start by creating a variable `message` - +let greeting = "My name is "; +let myName = "Meysam Arshadi"; +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..e81a768d3 100644 --- a/exercises/F-strings-methods/exercise.js +++ b/exercises/F-strings-methods/exercise.js @@ -1,3 +1,6 @@ // Start by creating a variable `message` - +let name = "Daniel"; +let nameLength = name.length; +let message = + "My name is " + name + " and it is " + nameLength + " charachter."; console.log(message); diff --git a/exercises/F-strings-methods/exercise2.js b/exercises/F-strings-methods/exercise2.js index b4b46943d..6e2067f96 100644 --- a/exercises/F-strings-methods/exercise2.js +++ b/exercises/F-strings-methods/exercise2.js @@ -1,3 +1,5 @@ -const name = " Daniel "; - +const name = "Daniel"; +let nameLength = name.length; +let message = + "My name is " + name + " and it is " + nameLength + " charachter."; console.log(message); diff --git a/exercises/G-numbers/exercise.js b/exercises/G-numbers/exercise.js index 49e7bc00b..8eee41c15 100644 --- a/exercises/G-numbers/exercise.js +++ b/exercises/G-numbers/exercise.js @@ -1 +1,13 @@ // Start by creating a variables `numberOfStudents` and `numberOfMentors` +let numberOfStudents = 15; +let studentMessage = "Total No of students: " + numberOfStudents; +console.log(studentMessage); + +let numberOfMentors = 5; +let mentorsMessage = "Total No of mentors: " + numberOfMentors; +console.log(mentorsMessage); + +let total = numberOfStudents + numberOfMentors; +let message = "Total number of students and mentors: " + total; + +console.log(message); diff --git a/exercises/I-floats/exercise.js b/exercises/I-floats/exercise.js index a5bbcd852..1603d6797 100644 --- a/exercises/I-floats/exercise.js +++ b/exercises/I-floats/exercise.js @@ -1,2 +1,8 @@ -var numberOfStudents = 15; -var numberOfMentors = 8; +let numberOfStudents = 15; +let numberOfMentors = 8; +let total = numberOfStudents + numberOfMentors; +console.log("Total:" + " " + total); +let studentPercentage = (numberOfStudents * 100) / total; +console.log("Student percentage:" + " %" + Math.round(studentPercentage)); +let mentorPercentage = (numberOfMentors * 100) / total; +console.log("Mentor percentage:" + " %" + Math.round(mentorPercentage)); diff --git a/exercises/J-functions/exercise.js b/exercises/J-functions/exercise.js index 0ae5850e5..ddfb95cdf 100644 --- a/exercises/J-functions/exercise.js +++ b/exercises/J-functions/exercise.js @@ -1,7 +1,7 @@ function halve(number) { - // complete the function here + return (number = number / 2); } -var result = halve(12); +var result = halve(125698); console.log(result); diff --git a/exercises/J-functions/exercise2.js b/exercises/J-functions/exercise2.js index 82ef5e780..0db520c10 100644 --- a/exercises/J-functions/exercise2.js +++ b/exercises/J-functions/exercise2.js @@ -1,5 +1,5 @@ function triple(number) { - // complete function here + return (number = number * 3); } var result = triple(12); diff --git a/exercises/K-functions-parameters/exercise.js b/exercises/K-functions-parameters/exercise.js index 8d5db5e69..6bf6d8de1 100644 --- a/exercises/K-functions-parameters/exercise.js +++ b/exercises/K-functions-parameters/exercise.js @@ -1,9 +1,10 @@ -// Complete the function so that it takes input parameters -function multiply() { - // Calculate the result of the function and return it +function logGreeting(name) { + let captalizedName = name.toUpperCase(); + return "HELLO " + captalizedName; } -// Assign the result of calling the function the variable `result` -var result = multiply(3, 4); - -console.log(result); +console.log(logGreeting("Daniel")); +console.log(logGreeting("Irina")); +console.log(logGreeting("Mimi")); +console.log(logGreeting("Rob")); +console.log(logGreeting("Yohannes")); diff --git a/exercises/K-functions-parameters/exercise2.js b/exercises/K-functions-parameters/exercise2.js index db7a8904b..bf00ffed6 100644 --- a/exercises/K-functions-parameters/exercise2.js +++ b/exercises/K-functions-parameters/exercise2.js @@ -1,4 +1,7 @@ // Declare your function first +function divide(a, b) { + return (divide = a / b); +} var result = divide(3, 4); diff --git a/exercises/K-functions-parameters/exercise3.js b/exercises/K-functions-parameters/exercise3.js index 537e9f4ec..f076eb03e 100644 --- a/exercises/K-functions-parameters/exercise3.js +++ b/exercises/K-functions-parameters/exercise3.js @@ -1,4 +1,7 @@ // Write your function here +function createGreeting(name) { + return "My name is" + " " + name; +} var greeting = createGreeting("Daniel"); diff --git a/exercises/K-functions-parameters/exercise4.js b/exercises/K-functions-parameters/exercise4.js index 7ab44589e..321891679 100644 --- a/exercises/K-functions-parameters/exercise4.js +++ b/exercises/K-functions-parameters/exercise4.js @@ -1,5 +1,7 @@ // Declare your function first - +function addNumbers(a, b) { + return a + b; +} // Call the function and assign to a variable `sum` - +let sum = addNumbers(13, 124); console.log(sum); diff --git a/exercises/K-functions-parameters/exercise5.js b/exercises/K-functions-parameters/exercise5.js index 7c5bcd605..dd96e45c1 100644 --- a/exercises/K-functions-parameters/exercise5.js +++ b/exercises/K-functions-parameters/exercise5.js @@ -1,5 +1,16 @@ // Declare your function here - +function createLongGreeting(name, age) { + return ( + "Hello! My name is" + + " " + + name + + "and I am" + + " " + + age + + " " + + "year old." + ); +} const greeting = createLongGreeting("Daniel", 30); console.log(greeting); diff --git a/exercises/L-functions-nested/exercise.js b/exercises/L-functions-nested/exercise.js index a5d377442..6c1021aa0 100644 --- a/exercises/L-functions-nested/exercise.js +++ b/exercises/L-functions-nested/exercise.js @@ -3,3 +3,10 @@ var mentor2 = "Irina"; var mentor3 = "Mimi"; var mentor4 = "Rob"; var mentor5 = "Yohannes"; + +function logGreeting(name) { + let upperCaseName = name.upperCaseName; + return "HELLO" + upperCaseName; +} + +console.log(logGreeting); diff --git a/mandatory/1-syntax-errors.js b/mandatory/1-syntax-errors.js index a10cc9ac2..e4008a4e1 100644 --- a/mandatory/1-syntax-errors.js +++ b/mandatory/1-syntax-errors.js @@ -1,18 +1,24 @@ // There are syntax errors in this code - can you fix it to pass the tests? -function addNumbers(a b c) { - return a + b + c; +function addNumbers(a, b, c) { + let total = a + b + c; + return total; } -function introduceMe(name, age) - return "Hello, my name is " + name "and I am " age + "years old"; +console.log(addNumbers(3, 4, 6)); -function getTotal(a, b) { - total = a ++ b; +function introduceMe(name, age) { + return "Hello, my name is " + name + " and I am " + age + " years old"; +} - return "The total is total"; +console.log(introduceMe("Sonjide", 27)); + +function getTotal(a, b) { + total = a + b; + return "The total is " + total; } +console.log(getTotal(23, 5)); /* =================================================== ======= TESTS - DO NOT MODIFY BELOW THIS LINE ===== diff --git a/mandatory/2-logic-error.js b/mandatory/2-logic-error.js index 9cca7603b..b61092aa2 100644 --- a/mandatory/2-logic-error.js +++ b/mandatory/2-logic-error.js @@ -1,18 +1,24 @@ // 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(); } +console.log(trimWord(" CodeYourFuture ")); +console.log(trimWord(" CodeYourFuture teaches coding ")); + function getStringLength(word) { - return "word".length(); + return word.length; } +console.log(getStringLength("Turtles")); +console.log(getStringLength("A wild sentence appeared!")); + function multiply(a, b, c) { - a * b * c; - return; + return a * b * c; } +console.log(multiply(2, 3, 6)); /* =================================================== ======= TESTS - DO NOT MODIFY BELOW THIS LINE ===== diff --git a/mandatory/3-function-output.js b/mandatory/3-function-output.js index 5a953ba60..6b948b86c 100644 --- a/mandatory/3-function-output.js +++ b/mandatory/3-function-output.js @@ -1,18 +1,26 @@ // Add comments to explain what this function does. You're meant to use Google! +// My answer: The Math.random() function returns a floating-point, pseudo-random number that's greater than or equal to 0 and less than 1, with approximately uniform distribution over that range — which you can then scale to your desired range. The implementation selects the initial seed to the random number generation algorithm; it cannot be chosen or reset by the user. + function getRandomNumber() { return Math.random() * 10; } // Add comments to explain what this function does. You're meant to use Google! +// My answer: In JavaScript, concat() is a string method that is used to concatenate strings together. The concat() method appends one or more string values to the calling string and then returns the concatenated result as a new string. Because the concat() method is a method of the String object, it must be invoked through a particular instance of the String class. + function combine2Words(word1, word2) { return word1.concat(word2); } function concatenate(firstWord, secondWord, thirdWord) { + return firstWord.concat(" ", secondWord.concat(" ", thirdWord)); // Write the body of this function to concatenate three words together. // Look at the test case below to understand what this function is expected to return. } +console.log(concatenate("code", "your", "future")); +console.log(concatenate("I ", "like ", "pizza")); + /* =================================================== ======= TESTS - DO NOT MODIFY BELOW THIS LINE ===== diff --git a/mandatory/4-tax.js b/mandatory/4-tax.js index ba77c7ae2..7bda10e6f 100644 --- a/mandatory/4-tax.js +++ b/mandatory/4-tax.js @@ -5,8 +5,14 @@ Sales tax is 20% of the price of the product. */ -function calculateSalesTax() {} - +function calculateSalesTax(price) { + const itemTax = (price * 20) / 100; + const total = itemTax + price; + return total; +} +console.log(calculateSalesTax(15)); +console.log(calculateSalesTax(17.5)); +console.log(calculateSalesTax(34)); /* CURRENCY FORMATTING =================== @@ -17,7 +23,15 @@ function calculateSalesTax() {} Remember that the prices must include the sales tax (hint: you already wrote a function for this!) */ -function addTaxAndFormatCurrency() {} +function addTaxAndFormatCurrency(price) { + const itemTax = (price * 20) / 100; + const total = itemTax + price; + return "£" + total.toFixed(2); +} + +console.log(addTaxAndFormatCurrency(15)); +console.log(addTaxAndFormatCurrency(17.5)); +console.log(addTaxAndFormatCurrency(34)); /* =================================================== From 755c7da332511f3a03e40829372ae0364e58797d Mon Sep 17 00:00:00 2001 From: Meysam Arshadi Date: Thu, 24 Nov 2022 18:06:25 +0000 Subject: [PATCH 2/2] Final Commite --- package.json | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 93e0861e3..9e7f2ffeb 100644 --- a/package.json +++ b/package.json @@ -14,15 +14,21 @@ "url": "https://github.com/CodeYourFuture/JavaScript-Core-1-Coursework-Week1/issues" }, "jest": { - "setupFilesAfterEnv": ["jest-extended"], + "setupFilesAfterEnv": [ + "jest-extended" + ], "projects": [ { "displayName": "mandatory", - "testMatch": ["/mandatory/*.js"] + "testMatch": [ + "/mandatory/*.js" + ] }, { "displayName": "extra", - "testMatch": ["/extra/*.js"] + "testMatch": [ + "/extra/*.js" + ] } ] },