From 64c365ede62ece6111e953a39d7255d4487f6cab Mon Sep 17 00:00:00 2001 From: maham511 Date: Sun, 20 Jun 2021 19:30:31 +0100 Subject: [PATCH 1/9] Passed test on 1-syntax-errors.js, 2-logic-error.js fixed last error --- .vscode/settings.json | 6 ++++++ mandatory/1-syntax-errors.js | 12 ++++++------ mandatory/2-logic-error.js | 7 +++---- package.json | 4 +++- 4 files changed, 18 insertions(+), 11 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..26e2019f2 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,6 @@ +{ + "cSpell.words": [ + "Sonjide", + "wordtrim" + ] +} \ No newline at end of file diff --git a/mandatory/1-syntax-errors.js b/mandatory/1-syntax-errors.js index a10cc9ac2..cc9c2abf1 100644 --- a/mandatory/1-syntax-errors.js +++ b/mandatory/1-syntax-errors.js @@ -1,16 +1,16 @@ // 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 getTotal(a, b) { - total = a ++ b; - - return "The total is total"; + total = a + b; + return "The total is " + total; } /* diff --git a/mandatory/2-logic-error.js b/mandatory/2-logic-error.js index b90d41dd1..c7d282ef4 100644 --- a/mandatory/2-logic-error.js +++ b/mandatory/2-logic-error.js @@ -4,13 +4,12 @@ function trimWord(word) { return wordtrim(); } -function getWordLength(word) { - return "word".length(); +function getStringLength(word) { + return word.length(); } function multiply(a, b, c) { - a * b * c; - return; + return a * b * c; } /* diff --git a/package.json b/package.json index 58555936d..778df9683 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,9 @@ "url": "https://github.com/CodeYourFuture/JavaScript-Core-1-Coursework-Week1/issues" }, "jest": { - "setupFilesAfterEnv": ["jest-extended"] + "setupFilesAfterEnv": [ + "jest-extended" + ] }, "homepage": "https://github.com/CodeYourFuture/JavaScript-Core-1-Coursework-Week1#readme", "devDependencies": { From ff2b393b8a54c3928ca3d1d73985bec18046cc0a Mon Sep 17 00:00:00 2001 From: maham511 Date: Sun, 20 Jun 2021 19:52:32 +0100 Subject: [PATCH 2/9] comment added to 2-logic-error.js --- mandatory/2-logic-error.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mandatory/2-logic-error.js b/mandatory/2-logic-error.js index c7d282ef4..14b9f982a 100644 --- a/mandatory/2-logic-error.js +++ b/mandatory/2-logic-error.js @@ -1,5 +1,9 @@ // The syntax for this function is valid but it has an error, find it and fix it. +function wordtrim(){ + return " hi afafaf"; //maybe need If Statements with numbers???? +} + function trimWord(word) { return wordtrim(); } From 5a8f8034cf60f9040de655b024df25cae6899bba Mon Sep 17 00:00:00 2001 From: maham511 Date: Sun, 20 Jun 2021 20:27:00 +0100 Subject: [PATCH 3/9] Passed test on 3-function-output.js and comments added. Task 3 complete --- mandatory/3-function-output.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/mandatory/3-function-output.js b/mandatory/3-function-output.js index 5a953ba60..882e08796 100644 --- a/mandatory/3-function-output.js +++ b/mandatory/3-function-output.js @@ -1,16 +1,17 @@ -// Add comments to explain what this function does. You're meant to use Google! +//My Comment - This function gives a random number by using math.random() and multiplying the value by 10 function getRandomNumber() { return Math.random() * 10; } -// Add comments to explain what this function does. You're meant to use Google! + +//My comment - The function combines two words using the concat method. function combine2Words(word1, word2) { return word1.concat(word2); } 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. + return firstWord + " " + secondWord + " " + thirdWord; } /* From 58cb84a2e0412affb18b1b96b35b7b4383503382 Mon Sep 17 00:00:00 2001 From: maham511 Date: Sun, 20 Jun 2021 20:47:32 +0100 Subject: [PATCH 4/9] Updated 3-function-output.js, used simpler concatenation --- mandatory/3-function-output.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mandatory/3-function-output.js b/mandatory/3-function-output.js index 882e08796..100c97644 100644 --- a/mandatory/3-function-output.js +++ b/mandatory/3-function-output.js @@ -10,9 +10,10 @@ function combine2Words(word1, word2) { } function concatenate(firstWord, secondWord, thirdWord) { - // Write the body of this function to concatenate three words together. - return firstWord + " " + secondWord + " " + thirdWord; + return `${firstWord} ${secondWord} ${thirdWord}`; } +/*Can also be written this way: + return firstWord + " " + secondWord + " " + thirdWord; */ /* =================================================== From 594881b07bb6715f14d55215242146f474fcf88c Mon Sep 17 00:00:00 2001 From: maham511 Date: Mon, 21 Jun 2021 15:31:41 +0100 Subject: [PATCH 5/9] Exercises done upto F-strings-methods --- exercises/C-variables/exercise.js | 3 +++ exercises/D-strings/exercise.js | 3 +++ exercises/E-strings-concatenation/exercise.js | 7 ++++++- exercises/F-strings-methods/exercise.js | 10 ++++++++++ exercises/F-strings-methods/exercise2.js | 5 +++++ 5 files changed, 27 insertions(+), 1 deletion(-) diff --git a/exercises/C-variables/exercise.js b/exercises/C-variables/exercise.js index a6bbb9786..a6fb2dd53 100644 --- a/exercises/C-variables/exercise.js +++ b/exercises/C-variables/exercise.js @@ -1,3 +1,6 @@ // Start by creating a variable `greeting` +var greeting = "Hello World!! :D" 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..71db29d50 100644 --- a/exercises/D-strings/exercise.js +++ b/exercises/D-strings/exercise.js @@ -1,3 +1,6 @@ // Start by creating a variable `message` +var message = "Message in a bottle"; +var 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..3ade83823 100644 --- a/exercises/E-strings-concatenation/exercise.js +++ b/exercises/E-strings-concatenation/exercise.js @@ -1,3 +1,8 @@ // Start by creating a variable `message` -console.log(message); +var greetingStart = "Bonjour, je m'appelle "; +var myName = "Maha"; + +var greeting = greetingStart + myName; + +console.log(greeting); diff --git a/exercises/F-strings-methods/exercise.js b/exercises/F-strings-methods/exercise.js index 2cffa6a81..0c9c1d33f 100644 --- a/exercises/F-strings-methods/exercise.js +++ b/exercises/F-strings-methods/exercise.js @@ -1,3 +1,13 @@ // Start by creating a variable `message` +var message; +var myName = "Maha"; +var nameLength = myName.length; +message = + "My name is " + + myName + + " and my name is only " + + nameLength + + " characters long"; + console.log(message); diff --git a/exercises/F-strings-methods/exercise2.js b/exercises/F-strings-methods/exercise2.js index b4b46943d..24f64935e 100644 --- a/exercises/F-strings-methods/exercise2.js +++ b/exercises/F-strings-methods/exercise2.js @@ -1,3 +1,8 @@ const name = " Daniel "; +const nameLength = name.length; +const nameTrim = name.trim(); + +message = + "My name is " + name.trim() + " and my name is " + nameLength + " characters long"; console.log(message); From 0e328a41fe4634a0845693c888506ce285ea258c Mon Sep 17 00:00:00 2001 From: maham511 Date: Mon, 21 Jun 2021 20:29:17 +0100 Subject: [PATCH 6/9] Finished exercise task till I-Floats --- exercises/G-numbers/exercise.js | 7 +++++++ exercises/I-floats/exercise.js | 11 +++++++++++ 2 files changed, 18 insertions(+) diff --git a/exercises/G-numbers/exercise.js b/exercises/G-numbers/exercise.js index 49e7bc00b..1d204c17a 100644 --- a/exercises/G-numbers/exercise.js +++ b/exercises/G-numbers/exercise.js @@ -1 +1,8 @@ // Start by creating a variables `numberOfStudents` and `numberOfMentors` + +const numberOfStudents = 12; +const numberOfMentors = 9; + +const total = numberOfStudents + numberOfMentors; + +console.log(total); diff --git a/exercises/I-floats/exercise.js b/exercises/I-floats/exercise.js index a5bbcd852..076244686 100644 --- a/exercises/I-floats/exercise.js +++ b/exercises/I-floats/exercise.js @@ -1,2 +1,13 @@ var numberOfStudents = 15; var numberOfMentors = 8; + +var totalNumber = numberOfMentors + numberOfStudents; + +var studentPercentage = numberOfStudents / totalNumber * 100; +var mentorsPercentage = numberOfMentors / totalNumber * 100; + +var roundedStudentPercentage = Math.round(studentPercentage); +var roundedMentorsPercentage = Math.round(mentorsPercentage); + + console.log("Percentage student: " + roundedStudentPercentage + "%"); + console.log("Percentage mentors: " + roundedMentorsPercentage + "%"); From 10ad651ee8782197fe83f960d7a2f4fb9abd9931 Mon Sep 17 00:00:00 2001 From: maham511 Date: Tue, 22 Jun 2021 12:50:06 +0100 Subject: [PATCH 7/9] Finished all exercises tasks. L may need updating --- exercises/F-strings-methods/exercise2.js | 4 +-- exercises/J-functions/exercise.js | 1 + exercises/J-functions/exercise2.js | 1 + exercises/K-functions-parameters/exercise.js | 3 +- exercises/K-functions-parameters/exercise2.js | 3 ++ exercises/K-functions-parameters/exercise3.js | 3 ++ exercises/K-functions-parameters/exercise4.js | 4 +++ exercises/K-functions-parameters/exercise5.js | 3 ++ exercises/L-functions-nested/exercise.js | 31 +++++++++++++++++++ 9 files changed, 50 insertions(+), 3 deletions(-) diff --git a/exercises/F-strings-methods/exercise2.js b/exercises/F-strings-methods/exercise2.js index 24f64935e..06b9ce1e0 100644 --- a/exercises/F-strings-methods/exercise2.js +++ b/exercises/F-strings-methods/exercise2.js @@ -1,8 +1,8 @@ const name = " Daniel "; -const nameLength = name.length; const nameTrim = name.trim(); +const nameLength = nameTrim.length; message = - "My name is " + name.trim() + " and my name is " + nameLength + " characters long"; + "My name is " + nameTrim + " and my name is " + nameLength + " characters long"; console.log(message); diff --git a/exercises/J-functions/exercise.js b/exercises/J-functions/exercise.js index 0ae5850e5..e9ba2f0ef 100644 --- a/exercises/J-functions/exercise.js +++ b/exercises/J-functions/exercise.js @@ -1,5 +1,6 @@ function halve(number) { // complete the function here + return number/2; } var result = halve(12); diff --git a/exercises/J-functions/exercise2.js b/exercises/J-functions/exercise2.js index 82ef5e780..6d216ffc6 100644 --- a/exercises/J-functions/exercise2.js +++ b/exercises/J-functions/exercise2.js @@ -1,5 +1,6 @@ function triple(number) { // complete function here + return number*3; } var result = triple(12); diff --git a/exercises/K-functions-parameters/exercise.js b/exercises/K-functions-parameters/exercise.js index 8d5db5e69..a4eed9d76 100644 --- a/exercises/K-functions-parameters/exercise.js +++ b/exercises/K-functions-parameters/exercise.js @@ -1,6 +1,7 @@ // Complete the function so that it takes input parameters -function multiply() { +function multiply(num1, num2) { // Calculate the result of the function and return it + 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..ab4102430 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 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..0d4027979 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 `${"Hello, 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..2bf04d32e 100644 --- a/exercises/K-functions-parameters/exercise4.js +++ b/exercises/K-functions-parameters/exercise4.js @@ -1,5 +1,9 @@ // Declare your function first +function addNum(a, b) { + return a + b; +} // Call the function and assign to a variable `sum` +var sum = addNum(13, 124); console.log(sum); diff --git a/exercises/K-functions-parameters/exercise5.js b/exercises/K-functions-parameters/exercise5.js index 7c5bcd605..9c614dd98 100644 --- a/exercises/K-functions-parameters/exercise5.js +++ b/exercises/K-functions-parameters/exercise5.js @@ -1,4 +1,7 @@ // Declare your function here +function createLongGreeting(name, age){ + return `${"Hello, my name is"} ${name} ${"and I'm"} ${age} ${"years old"}`; +} const greeting = createLongGreeting("Daniel", 30); diff --git a/exercises/L-functions-nested/exercise.js b/exercises/L-functions-nested/exercise.js index a5d377442..4f3a89b14 100644 --- a/exercises/L-functions-nested/exercise.js +++ b/exercises/L-functions-nested/exercise.js @@ -3,3 +3,34 @@ var mentor2 = "Irina"; var mentor3 = "Mimi"; var mentor4 = "Rob"; var mentor5 = "Yohannes"; + +//THIS SHOULD WORK! +function createGreeting(name) { + var greeting = `Helloooo ${name}`; + return greeting.toUpperCase(); +} + +console.log(createGreeting(mentor1)); +console.log(createGreeting(mentor2)); +console.log(createGreeting(mentor3)); +console.log(createGreeting(mentor4)); +// console.log(createGreeting(mentor5)); + +//UPTO HERE + +// // function CreateShoutyGreeting(){ +// // return createGreeting.toUpperCase(); +// // } + +// CREATES ALL CAPS FOR A NAME and logs +// function createCapName(name){ +// return name.toUpperCase(); +// } +// // console.log(createCapName(mentor4)); + +// function createShoutyGreeting(name){ +// var message = createCapName(name); +// return `Hello ${name}`; +// } +// console.log(createShoutyGreeting(mentor4)); + From 711193bc971aad2c3db0b5f4f0437a99e2292f0f Mon Sep 17 00:00:00 2001 From: maham511 Date: Tue, 22 Jun 2021 15:24:53 +0100 Subject: [PATCH 8/9] Finished mandatory tasks, all tests passed --- mandatory/2-logic-error.js | 8 ++------ mandatory/4-tax.js | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/mandatory/2-logic-error.js b/mandatory/2-logic-error.js index 14b9f982a..37c4ebc15 100644 --- a/mandatory/2-logic-error.js +++ b/mandatory/2-logic-error.js @@ -1,15 +1,11 @@ // The syntax for this function is valid but it has an error, find it and fix it. -function wordtrim(){ - return " hi afafaf"; //maybe need If Statements with numbers???? -} - function trimWord(word) { - return wordtrim(); + return word.trim(); } function getStringLength(word) { - return word.length(); + return word.length; } function multiply(a, b, c) { diff --git a/mandatory/4-tax.js b/mandatory/4-tax.js index ba77c7ae2..fe92cfa10 100644 --- a/mandatory/4-tax.js +++ b/mandatory/4-tax.js @@ -5,7 +5,9 @@ Sales tax is 20% of the price of the product. */ -function calculateSalesTax() {} +function calculateSalesTax(num) { + return num *1.2; //Adds 20% to number and gives total price including tax +} /* CURRENCY FORMATTING @@ -15,9 +17,18 @@ function calculateSalesTax() {} Write a function that adds tax to a number, and then transforms the total into the format £0.00 Remember that the prices must include the sales tax (hint: you already wrote a function for this!) + */ -function addTaxAndFormatCurrency() {} +function addTaxAndFormatCurrency(num) { + return `£${calculateSalesTax(num).toFixed(2)}`; +} + +//CAN ALSO WRITE THIS WAY: +// function addTaxAndFormatCurrency(num) { +// var totalPrice= `£${calculateSalesTax(num).toFixed(2)}`; +// return totalPrice; +// } /* =================================================== From c87a9b161759332c19de1c78726bb32439aaab65 Mon Sep 17 00:00:00 2001 From: maham511 Date: Thu, 24 Jun 2021 23:42:06 +0100 Subject: [PATCH 9/9] Passed all tests in 1-currency-conversion.js in 'Extra' --- extra/1-currency-conversion.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/extra/1-currency-conversion.js b/extra/1-currency-conversion.js index 07391e15f..c71fa36ec 100644 --- a/extra/1-currency-conversion.js +++ b/extra/1-currency-conversion.js @@ -5,7 +5,9 @@ Write a function that converts a price to USD (exchange rate is 1.4 $ to £) */ -function convertToUSD() {} +function convertToUSD(pounds) { + return pounds * 1.4; +} /* CURRENCY FORMATTING @@ -15,8 +17,13 @@ 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(pounds) { + var brReal = pounds * 5.7; + var totalAfterFee = brazReal * 0.99; + var totalWithDec = totalAfterFee.toFixed(2); + var finalTotalFee = parseFloat(totalWithDec); + return finalTotalFee; +} /* ======= TESTS - DO NOT MODIFY ===== There are some Tests in this file that will help you work out if your code is working.