From ab101830914114f3ac7cc5925092052b0b063eaf Mon Sep 17 00:00:00 2001 From: Mari Azh Date: Mon, 21 Nov 2022 14:51:11 +0000 Subject: [PATCH 1/4] JavaScript-Core-1-Coursework-Week1 --- mandatory/1-syntax-errors.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mandatory/1-syntax-errors.js b/mandatory/1-syntax-errors.js index a10cc9ac2..a5b071389 100644 --- a/mandatory/1-syntax-errors.js +++ b/mandatory/1-syntax-errors.js @@ -1,6 +1,6 @@ // 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; } From c0a17a64bb4cb6e834cd364a232bea5fc32d5cb2 Mon Sep 17 00:00:00 2001 From: Mari Azh Date: Wed, 23 Nov 2022 11:55:00 +0000 Subject: [PATCH 2/4] London 9 -Marziyeh Azhdari - JS-Core-1 - Week 1 --- exercises/A-setup-ide/README.md | 2 +- exercises/B-hello-world/exercise.js | 5 ++++ exercises/C-variables/exercise.js | 3 +++ exercises/D-strings/exercise.js | 6 +++-- exercises/E-strings-concatenation/exercise.js | 4 +++- exercises/F-strings-methods/exercise.js | 5 +++- exercises/F-strings-methods/exercise2.js | 8 ++++--- exercises/G-numbers/exercise.js | 6 +++++ exercises/I-floats/exercise.js | 9 ++++++-- exercises/J-functions/exercise.js | 4 ++-- exercises/J-functions/exercise2.js | 2 +- exercises/K-functions-parameters/README.md | 2 +- exercises/K-functions-parameters/exercise.js | 4 ++-- exercises/K-functions-parameters/exercise2.js | 4 +++- exercises/K-functions-parameters/exercise3.js | 6 +++-- exercises/K-functions-parameters/exercise4.js | 6 +++-- exercises/K-functions-parameters/exercise5.js | 6 +++-- exercises/L-functions-nested/exercise.js | 23 +++++++++++++++---- extra/1-currency-conversion.js | 13 ++++++++--- extra/2-piping.js | 16 ++++++++----- mandatory/1-syntax-errors.js | 19 ++++++++------- mandatory/2-logic-error.js | 15 ++++++++---- mandatory/3-function-output.js | 7 ++++++ mandatory/4-tax.js | 15 +++++++++--- package.json | 12 +++++++--- 25 files changed, 146 insertions(+), 56 deletions(-) diff --git a/exercises/A-setup-ide/README.md b/exercises/A-setup-ide/README.md index de230419b..2f56c45bb 100644 --- a/exercises/A-setup-ide/README.md +++ b/exercises/A-setup-ide/README.md @@ -1,4 +1,4 @@ -There are some tools that will help you to write code. One of these, [Prettier](https://prettier.io/), formats your code, making it easier for you and others to read. +There are some tools that will help you to write code. One of these, [Prettier](https:react//prettier.io/), formats your code, making it easier for you and others to read. ### 1. Install prettier diff --git a/exercises/B-hello-world/exercise.js b/exercises/B-hello-world/exercise.js index b179ee953..891fef275 100644 --- a/exercises/B-hello-world/exercise.js +++ b/exercises/B-hello-world/exercise.js @@ -1 +1,6 @@ console.log("Hello world"); +console.log("cd exercises/B-hello-world") +console.log(`This is my first coding week`) +console.log('Hello World. I just started learning JavaScript!') +console.log(29) + diff --git a/exercises/C-variables/exercise.js b/exercises/C-variables/exercise.js index a6bbb9786..c10bfe8d8 100644 --- a/exercises/C-variables/exercise.js +++ b/exercises/C-variables/exercise.js @@ -1,3 +1,6 @@ // Start by creating a variable `greeting` + const 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..d85b510b8 100644 --- a/exercises/D-strings/exercise.js +++ b/exercises/D-strings/exercise.js @@ -1,3 +1,5 @@ // Start by creating a variable `message` - -console.log(message); +let message="This is a string" +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..d2c5cee7d 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 first="Hello, my name is " +let myName="Mari" +let message=first+myName console.log(message); diff --git a/exercises/F-strings-methods/exercise.js b/exercises/F-strings-methods/exercise.js index 2cffa6a81..e0101ed6d 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 myName="mari" +let lengthName=myName.length +let message="My name is "+myName+" and my name is " + lengthName+" characters long" console.log(message); + diff --git a/exercises/F-strings-methods/exercise2.js b/exercises/F-strings-methods/exercise2.js index b4b46943d..8f880cbf9 100644 --- a/exercises/F-strings-methods/exercise2.js +++ b/exercises/F-strings-methods/exercise2.js @@ -1,3 +1,5 @@ -const name = " Daniel "; - -console.log(message); +let myName="mari" +let lengthName=myName.length +// let messageTwo=`my name is${myName}and my name is${lengthName}characters long` +let message=" My name is"+myName+" and my name is " + lengthName+" characters long" +console.log(message.trim()); diff --git a/exercises/G-numbers/exercise.js b/exercises/G-numbers/exercise.js index 49e7bc00b..bb65d0be8 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 total=numberOfMentors+numberOfStudents +console.log(numberOfStudents) +console.log(numberOfMentors) +console.log(total) \ No newline at end of file diff --git a/exercises/I-floats/exercise.js b/exercises/I-floats/exercise.js index a5bbcd852..89711eb7d 100644 --- a/exercises/I-floats/exercise.js +++ b/exercises/I-floats/exercise.js @@ -1,2 +1,7 @@ -var numberOfStudents = 15; -var numberOfMentors = 8; +let numberOfStudents = 15; +let numberOfMentors = 8; +let total=numberOfMentors+numberOfStudents +let percentageOfStudent=numberOfStudents/total*100; +console.log("Percentage students: "+Math.round(percentageOfStudent)+"%"); +let PercentageMentors=100-percentageOfStudent +console.log("Percentage mentors: "+Math.round(PercentageMentors)+"%"); diff --git a/exercises/J-functions/exercise.js b/exercises/J-functions/exercise.js index 0ae5850e5..8ae9a066e 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/2 } -var result = halve(12); +let result = halve(12); console.log(result); diff --git a/exercises/J-functions/exercise2.js b/exercises/J-functions/exercise2.js index 82ef5e780..9b1665f53 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*3 } var result = triple(12); diff --git a/exercises/K-functions-parameters/README.md b/exercises/K-functions-parameters/README.md index 1614e221b..df61925c4 100644 --- a/exercises/K-functions-parameters/README.md +++ b/exercises/K-functions-parameters/README.md @@ -45,7 +45,7 @@ function add(num1, num2) { ## Expected result ``` -Hello, my name is Daniel +Hello,my name is ;Daniel ``` ## Exercise 4 diff --git a/exercises/K-functions-parameters/exercise.js b/exercises/K-functions-parameters/exercise.js index 8d5db5e69..1c4947028 100644 --- a/exercises/K-functions-parameters/exercise.js +++ b/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(num1,num2) { + return num1*num2; } // Assign the result of calling the function the variable `result` diff --git a/exercises/K-functions-parameters/exercise2.js b/exercises/K-functions-parameters/exercise2.js index db7a8904b..7f1c09790 100644 --- a/exercises/K-functions-parameters/exercise2.js +++ b/exercises/K-functions-parameters/exercise2.js @@ -1,5 +1,7 @@ // Declare your function first - +function divide(num1,num2) { +return num1 / num2; +} var result = divide(3, 4); console.log(result); diff --git a/exercises/K-functions-parameters/exercise3.js b/exercises/K-functions-parameters/exercise3.js index 537e9f4ec..99cf31474 100644 --- a/exercises/K-functions-parameters/exercise3.js +++ b/exercises/K-functions-parameters/exercise3.js @@ -1,5 +1,7 @@ // Write your function here +function greeting(name){ + console.log("Hello,my name is ;"+(name)); +} +greeting("Daniel") -var greeting = createGreeting("Daniel"); -console.log(greeting); diff --git a/exercises/K-functions-parameters/exercise4.js b/exercises/K-functions-parameters/exercise4.js index 7ab44589e..6478f57bd 100644 --- a/exercises/K-functions-parameters/exercise4.js +++ b/exercises/K-functions-parameters/exercise4.js @@ -1,5 +1,7 @@ // Declare your function first - +function sum(num1,num2){ + return num1+num2 +} // Call the function and assign to a variable `sum` -console.log(sum); +console.log(sum(13,124)); diff --git a/exercises/K-functions-parameters/exercise5.js b/exercises/K-functions-parameters/exercise5.js index 7c5bcd605..20c75d299 100644 --- a/exercises/K-functions-parameters/exercise5.js +++ b/exercises/K-functions-parameters/exercise5.js @@ -1,5 +1,7 @@ // Declare your function here - -const greeting = createLongGreeting("Daniel", 30); +function createLongGreeting(name,age){ + return "Hello ,my name is "+name+"and i'm "+age+ " years 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..b57f8ced7 100644 --- a/exercises/L-functions-nested/exercise.js +++ b/exercises/L-functions-nested/exercise.js @@ -1,5 +1,18 @@ -var mentor1 = "Daniel"; -var mentor2 = "Irina"; -var mentor3 = "Mimi"; -var mentor4 = "Rob"; -var mentor5 = "Yohannes"; + +const mentor1 = "Daniel"; +const mentor2 = "Irina"; +const mentor3 = "Mimi"; +const mentor4 = "Rob"; +const mentor5 = "Yohannes"; + +function nameToUpperCase(name){ + return name.toUpperCase(); +} +function greeting(name){ + return `Hello ${nameToUpperCase(name)}`; +} +function result(name){ + return console.log(greeting(name)); +} +result(mentor1); +result(mentor3) \ No newline at end of file diff --git a/extra/1-currency-conversion.js b/extra/1-currency-conversion.js index 75b3c6aab..1a89d1cd2 100644 --- a/extra/1-currency-conversion.js +++ b/extra/1-currency-conversion.js @@ -5,7 +5,11 @@ Write a function that converts a price to USD (exchange rate is 1.4 $ to £) */ -function convertToUSD() {} +function convertToUSD(price) { + return price*1.4 +} +console.log(convertToUSD(32)) +console.log(convertToUSD(50)) /* CURRENCY CONVERSION @@ -15,8 +19,11 @@ 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(price) { + return price*5.7*0.99 +} +console.log(convertToBRL(30)) +console.log(convertToBRL(1.5)) /* ======= 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 b4f8c4c1b..1b009453e 100644 --- a/extra/2-piping.js +++ b/extra/2-piping.js @@ -16,21 +16,25 @@ the final result to the variable goodCode */ -function add() { - +function add(number1,number2) { +return number1+number2 } +console.log(add(1,3)) -function multiply() { - +function multiply(number1,number2) { +return number1*number2 } +console.log(multiply(2,3)) -function format() { - +function format(number) { +return `£${number}` } +console.log(format(16)) const startingValue = 2; // Why can this code be seen as bad practice? Comment your answer. +//there are three functions that are not necessary and I think it is possible with a shorter code as well.(I am not sure!!!!!!!!!!!!!!!!!) let badCode = /* BETTER PRACTICE */ diff --git a/mandatory/1-syntax-errors.js b/mandatory/1-syntax-errors.js index a5b071389..62ea97f99 100644 --- a/mandatory/1-syntax-errors.js +++ b/mandatory/1-syntax-errors.js @@ -3,17 +3,20 @@ function addNumbers(a, b ,c) { return a + b + c; } + console.log(addNumbers(3,4,6)) -function introduceMe(name, age) - return "Hello, my name is " + name "and I am " age + "years old"; -function getTotal(a, b) { - total = a ++ b; + function introduceMe(name, age){ + return `Hello ,my name is ${name} and I am ${age}years old`; + + } + console.log(introduceMe("Sonjide", 27)) - return "The total is total"; -} - -/* + function getTotal(a, b) { + const 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..5b9c460b1 100644 --- a/mandatory/2-logic-error.js +++ b/mandatory/2-logic-error.js @@ -1,18 +1,23 @@ // 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(2,3,6) +console.log(2,3,4) /* =================================================== ======= TESTS - DO NOT MODIFY BELOW THIS LINE ===== diff --git a/mandatory/3-function-output.js b/mandatory/3-function-output.js index 5a953ba60..f637e86df 100644 --- a/mandatory/3-function-output.js +++ b/mandatory/3-function-output.js @@ -1,17 +1,24 @@ // Add comments to explain what this function does. You're meant to use Google! +//The Math.random() function returns a floating-point, pseudo-random number that's greater than or equal to 0 and less than 1, function getRandomNumber() { return Math.random() * 10; } // Add comments to explain what this function does. You're meant to use Google! +//The concat() method is used to merge two or more arrays or any number or string. This method does not change the existing arrays, but instead returns a new array.in this example with concat word1 and word2 coming next to gether. function combine2Words(word1, word2) { return word1.concat(word2); } function concatenate(firstWord, secondWord, thirdWord) { + return firstWord.concat(" " + secondWord).concat(" " + thirdWord); + // return firstWord.concat(secondWord,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)) +console.log(concatenate(I,am,13)) /* =================================================== diff --git a/mandatory/4-tax.js b/mandatory/4-tax.js index ba77c7ae2..7321c3878 100644 --- a/mandatory/4-tax.js +++ b/mandatory/4-tax.js @@ -5,8 +5,12 @@ Sales tax is 20% of the price of the product. */ -function calculateSalesTax() {} - +function calculateSalesTax(price) { + return price*1.2 +} + console.log(calculateSalesTax(15)); + console.log(calculateSalesTax(17.50)); + console.log(calculateSalesTax(34)); /* CURRENCY FORMATTING =================== @@ -17,8 +21,13 @@ function calculateSalesTax() {} Remember that the prices must include the sales tax (hint: you already wrote a function for this!) */ -function addTaxAndFormatCurrency() {} +function addTaxAndFormatCurrency(price) { + return `£${(price * 1.2).toFixed(2)}`; +} +console.log(addTaxAndFormatCurrency(15)) +console.log(addTaxAndFormatCurrency(17.5)) +console.log(addTaxAndFormatCurrency(34)) /* =================================================== ======= TESTS - DO NOT MODIFY BELOW THIS LINE ===== 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" + ] } ] }, From ae1617757ea187c58900832100a12b120b75eb29 Mon Sep 17 00:00:00 2001 From: Mari Azh Date: Thu, 24 Nov 2022 19:29:22 +0000 Subject: [PATCH 3/4] week 1 --- mandatory/1-syntax-errors.js | 19 ++++++++++--------- mandatory/2-logic-error.js | 18 +++++++++--------- mandatory/3-function-output.js | 6 +++--- 3 files changed, 22 insertions(+), 21 deletions(-) diff --git a/mandatory/1-syntax-errors.js b/mandatory/1-syntax-errors.js index 62ea97f99..94f663cb2 100644 --- a/mandatory/1-syntax-errors.js +++ b/mandatory/1-syntax-errors.js @@ -3,20 +3,21 @@ function addNumbers(a, b ,c) { return a + b + c; } - console.log(addNumbers(3,4,6)) + function introduceMe(name, age){ - return `Hello ,my name is ${name} and I am ${age}years old`; - - } - console.log(introduceMe("Sonjide", 27)) + // return `Hello ,my name is ${name} and I am ${age} years old`; - function getTotal(a, b) { - const total = a +b; - return `The total is ${total}`; + return "Hello, my name is " + name + " and I am " + age + " years old"; } - console.log (getTotal(23,5)) + + + function getTotal(a,b) { + let total = a + b; + return `The total is ${total}`;} + +/* =================================================== ======= TESTS - DO NOT MODIFY BELOW THIS LINE ===== diff --git a/mandatory/2-logic-error.js b/mandatory/2-logic-error.js index 5b9c460b1..b5d66018c 100644 --- a/mandatory/2-logic-error.js +++ b/mandatory/2-logic-error.js @@ -1,23 +1,23 @@ // The syntax for this function is valid but it has an error, find it and fix it. -function trimWord(word) { - return word.trim; +function trimWord(word){ + return word.trim(); } -console.log(trimWord(" CodeYourFuture" )) -console.log(trimWord(" CodeYourFuture teaches coding ")) +// console.log(trimWord(" CodeYourFuture" )) +// console.log(trimWord(" CodeYourFuture teaches coding ")) -function getStringLength(word) { +function getStringLength(word){ return word.length; } -console.log(getStringLength("Turtles")) -console.log(getStringLength("A wild sentence appeared!")) +// console.log(getStringLength("Turtles")) +// console.log(getStringLength("A wild sentence appeared!")) function multiply(a, b, c) { return a * b * c; } -console,log(2,3,6) -console.log(2,3,4) +// console,log(2,3,6) +// console.log(2,3,4) /* =================================================== ======= TESTS - DO NOT MODIFY BELOW THIS LINE ===== diff --git a/mandatory/3-function-output.js b/mandatory/3-function-output.js index f637e86df..08a1b0985 100644 --- a/mandatory/3-function-output.js +++ b/mandatory/3-function-output.js @@ -16,9 +16,9 @@ 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 this function is expected to return. } -console.log(concatenate(code,your,future)) -console.log(concatenate(I,like,pizza)) -console.log(concatenate(I,am,13)) +// console.log(concatenate(code,your,future)) +// console.log(concatenate(I,like,pizza)) +// console.log(concatenate(I,am,13)) /* =================================================== From c66198293291f43d69b3d901188a3ed33c0e9b36 Mon Sep 17 00:00:00 2001 From: Mari Azh <80781901+MariAzhdari@users.noreply.github.com> Date: Mon, 28 Nov 2022 21:30:58 +0000 Subject: [PATCH 4/4] Update exercise3.js --- exercises/K-functions-parameters/exercise3.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/K-functions-parameters/exercise3.js b/exercises/K-functions-parameters/exercise3.js index 99cf31474..51c2949e3 100644 --- a/exercises/K-functions-parameters/exercise3.js +++ b/exercises/K-functions-parameters/exercise3.js @@ -1,6 +1,6 @@ // Write your function here function greeting(name){ - console.log("Hello,my name is ;"+(name)); + console.log("Hello,my name is ;"+ name); } greeting("Daniel")