From 83975104f4459f4eca1812c4b8855b91c09a7d0d Mon Sep 17 00:00:00 2001 From: BusraErdogan <90658195+BusraElmasErdogan@users.noreply.github.com> Date: Thu, 16 Dec 2021 12:49:40 +0000 Subject: [PATCH 1/3] Exercises exercises completed (A to L) --- exercises/B-hello-world/exercise.js | 2 +- 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 | 11 ++++++ exercises/G-numbers/README.md | 4 +- exercises/G-numbers/exercise.js | 10 +++++ exercises/I-floats/exercise.js | 14 ++++++- exercises/J-functions/exercise.js | 11 ++++-- exercises/J-functions/exercise2.js | 2 +- exercises/K-functions-parameters/exercise.js | 4 +- exercises/K-functions-parameters/exercise2.js | 6 ++- exercises/K-functions-parameters/exercise3.js | 6 ++- exercises/K-functions-parameters/exercise4.js | 6 ++- exercises/K-functions-parameters/exercise5.js | 4 +- exercises/L-functions-nested/exercise.js | 37 ++++++++++++++++--- 16 files changed, 103 insertions(+), 26 deletions(-) diff --git a/exercises/B-hello-world/exercise.js b/exercises/B-hello-world/exercise.js index b179ee953..50045ec4b 100644 --- a/exercises/B-hello-world/exercise.js +++ b/exercises/B-hello-world/exercise.js @@ -1 +1 @@ -console.log("Hello world"); +console.log(8, "Murat", "Busra"); diff --git a/exercises/C-variables/exercise.js b/exercises/C-variables/exercise.js index a6bbb9786..3ec45a62b 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); \ No newline at end of file diff --git a/exercises/D-strings/exercise.js b/exercises/D-strings/exercise.js index 2cffa6a81..617414e8a 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 a string"; +let messageType = typeof message; console.log(message); +console.log(messageType); \ No newline at end of file diff --git a/exercises/E-strings-concatenation/exercise.js b/exercises/E-strings-concatenation/exercise.js index 2cffa6a81..c0d23d710 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 messageStart = "Hello, my name is "; +let name = "Busra" +let message = messageStart + name; console.log(message); diff --git a/exercises/F-strings-methods/exercise.js b/exercises/F-strings-methods/exercise.js index 2cffa6a81..03c09574b 100644 --- a/exercises/F-strings-methods/exercise.js +++ b/exercises/F-strings-methods/exercise.js @@ -1,3 +1,14 @@ // Start by creating a variable `message` +let name = "Busra"; +let nameLength = name.length; +console.log(nameLength); + +let name1 = ' Busra ' +let messageStart = 'My name is '; +let messageEnd = " characters long"; +let message = messageStart + name + ' and '+ messageStart.toLocaleLowerCase() + nameLength + messageEnd; + +let messageTrimmed = messageStart + name1.trim() + ' and '+ messageStart.toLocaleLowerCase() + nameLength + messageEnd; console.log(message); +console.log(messageTrimmed); \ No newline at end of file diff --git a/exercises/G-numbers/README.md b/exercises/G-numbers/README.md index 76a79dab2..75136adf1 100644 --- a/exercises/G-numbers/README.md +++ b/exercises/G-numbers/README.md @@ -6,7 +6,7 @@ Unlike strings, numbers do not need to be wrapped in quotes. var age = 30; ``` -You can use mathematical operators to caclulate numbers: +You can use mathematical operators to calculate numbers: ```js var sum = 10 + 2; // 12 @@ -25,5 +25,5 @@ var difference = 10 - 2; // 8 ``` Number of students: 15 Number of mentors: 8 -Total numnber of students and mentors: 23 +Total number of students and mentors: 23 ``` diff --git a/exercises/G-numbers/exercise.js b/exercises/G-numbers/exercise.js index 49e7bc00b..b7c276275 100644 --- a/exercises/G-numbers/exercise.js +++ b/exercises/G-numbers/exercise.js @@ -1 +1,11 @@ // Start by creating a variables `numberOfStudents` and `numberOfMentors` + +let students = 'Number of students: '; +let numberOfStudents = 33 + 16; +console.log(students + numberOfStudents); +let mentors = "Number of mentors: "; +let numberOfMentors = 8 * 2; +console.log(mentors + numberOfMentors); +let totalText = 'Total number of students and mentors: '; +let total = numberOfMentors + numberOfStudents; +console.log(totalText + total); \ No newline at end of file diff --git a/exercises/I-floats/exercise.js b/exercises/I-floats/exercise.js index a5bbcd852..dd8a01406 100644 --- a/exercises/I-floats/exercise.js +++ b/exercises/I-floats/exercise.js @@ -1,2 +1,12 @@ -var numberOfStudents = 15; -var numberOfMentors = 8; +let numberOfStudents = 15; +let numberOfMentors = 8; + +let studentsText = 'Percentage students: ' +let percentageStudents = (15 / 23) * 100; +let roughPercentageStudents = Math.round(percentageStudents) + '%'; +console.log(studentsText + roughPercentageStudents); + +let mentorsText = 'Percentage mentors: ' +let percentageMentors = (8 / 23) * 100; +let roughPercentageMentors = Math.round (percentageMentors) + '%'; +console.log(mentorsText + roughPercentageMentors); \ No newline at end of file diff --git a/exercises/J-functions/exercise.js b/exercises/J-functions/exercise.js index 0ae5850e5..92e997444 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); +let result = halve(12); +let result1 = halve(6); +let result2 = halve(8); console.log(result); +console.log(result1); +console.log(result2); + diff --git a/exercises/J-functions/exercise2.js b/exercises/J-functions/exercise2.js index 82ef5e780..95ef62512 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/exercise.js b/exercises/K-functions-parameters/exercise.js index 8d5db5e69..4614501b1 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..ee68f58b2 100644 --- a/exercises/K-functions-parameters/exercise2.js +++ b/exercises/K-functions-parameters/exercise2.js @@ -1,5 +1,7 @@ // Declare your function first - -var result = divide(3, 4); +function divide (num1, num2) { + return num1 / num2; +}; +var result = divide(40, 4); console.log(result); diff --git a/exercises/K-functions-parameters/exercise3.js b/exercises/K-functions-parameters/exercise3.js index 537e9f4ec..239d0d035 100644 --- a/exercises/K-functions-parameters/exercise3.js +++ b/exercises/K-functions-parameters/exercise3.js @@ -1,5 +1,7 @@ // Write your function here - -var greeting = createGreeting("Daniel"); +function createGreeting (text) { +return 'Hello ' + text; +} +let greeting = createGreeting("Daniel"); console.log(greeting); diff --git a/exercises/K-functions-parameters/exercise4.js b/exercises/K-functions-parameters/exercise4.js index 7ab44589e..b97884572 100644 --- a/exercises/K-functions-parameters/exercise4.js +++ b/exercises/K-functions-parameters/exercise4.js @@ -1,5 +1,7 @@ // Declare your function first - +function add (num1, num2) { +return num1 + num2; +} // Call the function and assign to a variable `sum` - +let sum = add ( 13, 124); console.log(sum); diff --git a/exercises/K-functions-parameters/exercise5.js b/exercises/K-functions-parameters/exercise5.js index 7c5bcd605..6c05ba0f3 100644 --- a/exercises/K-functions-parameters/exercise5.js +++ b/exercises/K-functions-parameters/exercise5.js @@ -1,5 +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); console.log(greeting); diff --git a/exercises/L-functions-nested/exercise.js b/exercises/L-functions-nested/exercise.js index a5d377442..137bf030a 100644 --- a/exercises/L-functions-nested/exercise.js +++ b/exercises/L-functions-nested/exercise.js @@ -1,5 +1,32 @@ -var mentor1 = "Daniel"; -var mentor2 = "Irina"; -var mentor3 = "Mimi"; -var mentor4 = "Rob"; -var mentor5 = "Yohannes"; +let mentor1 = "Daniel"; +let mentor2 = "Irina"; +let mentor3 = "Mimi"; +let mentor4 = "Rob"; +let mentor5 = "Yohannes"; +let greeting = "Hello "; + + +function greetingMentors (grt, name){ + return grt + name; +}; + +let write = greetingMentors(greeting, mentor1); +let result = write.toUpperCase(); +console.log(result); + +write = greetingMentors(greeting, mentor2); +result = write.toUpperCase(); +console.log(result); + +write = greetingMentors(greeting, mentor3); +result = write.toUpperCase(); +console.log(result); + +write = greetingMentors(greeting, mentor4); +result = write.toUpperCase(); +console.log(result); + +write = greetingMentors(greeting, mentor5); +result = write.toUpperCase(); +console.log(result); + From 3de2a9973284033af003b05c3ba9e71824d95879 Mon Sep 17 00:00:00 2001 From: BusraErdogan <90658195+BusraElmasErdogan@users.noreply.github.com> Date: Thu, 16 Dec 2021 15:37:03 +0000 Subject: [PATCH 2/3] Mandatory completed mandatory completed (1 to 4) --- mandatory/1-syntax-errors.js | 12 ++++++------ mandatory/2-logic-error.js | 7 +++---- mandatory/3-function-output.js | 10 ++++++---- mandatory/4-tax.js | 10 +++++++--- 4 files changed, 22 insertions(+), 17 deletions(-) diff --git a/mandatory/1-syntax-errors.js b/mandatory/1-syntax-errors.js index a10cc9ac2..69f0dda58 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; + const total = a + b; - return "The total is total"; + return "The total is " + total; } /* diff --git a/mandatory/2-logic-error.js b/mandatory/2-logic-error.js index 9cca7603b..9f771735a 100644 --- a/mandatory/2-logic-error.js +++ b/mandatory/2-logic-error.js @@ -1,16 +1,15 @@ // 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 getStringLength(word) { - return "word".length(); + return word.length; } function multiply(a, b, c) { - a * b * c; - return; + return a * b * c ; } /* diff --git a/mandatory/3-function-output.js b/mandatory/3-function-output.js index 5a953ba60..79c135a96 100644 --- a/mandatory/3-function-output.js +++ b/mandatory/3-function-output.js @@ -1,18 +1,20 @@ -// Add comments to explain what this function does. You're meant to use Google! +// expected output: a number from 0 to <10 function getRandomNumber() { return Math.random() * 10; } -// Add comments to explain what this function does. You're meant to use Google! +// combine2words function joins two strings 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}`; } + +// 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. /* =================================================== ======= TESTS - DO NOT MODIFY BELOW THIS LINE ===== diff --git a/mandatory/4-tax.js b/mandatory/4-tax.js index ba77c7ae2..36855d589 100644 --- a/mandatory/4-tax.js +++ b/mandatory/4-tax.js @@ -5,8 +5,9 @@ Sales tax is 20% of the price of the product. */ -function calculateSalesTax() {} - +function calculateSalesTax(productPrice) { + return productPrice * 0.2 + productPrice; +}; /* CURRENCY FORMATTING =================== @@ -17,7 +18,10 @@ function calculateSalesTax() {} Remember that the prices must include the sales tax (hint: you already wrote a function for this!) */ -function addTaxAndFormatCurrency() {} +function addTaxAndFormatCurrency(productPrice) { + const total = productPrice + productPrice * 0.2 ; + return `£${total.toFixed(2)}`; +}; /* =================================================== From f1f6590efd31f8f2d75c8ade72c2a4ab34a8b977 Mon Sep 17 00:00:00 2001 From: BusraErdogan <90658195+BusraElmasErdogan@users.noreply.github.com> Date: Fri, 17 Dec 2021 20:45:52 +0000 Subject: [PATCH 3/3] some updates in exercises --- exercises/F-strings-methods/exercise.js | 5 ----- exercises/F-strings-methods/exercise2.js | 9 +++++++-- exercises/I-floats/exercise.js | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/exercises/F-strings-methods/exercise.js b/exercises/F-strings-methods/exercise.js index 03c09574b..74d5a3414 100644 --- a/exercises/F-strings-methods/exercise.js +++ b/exercises/F-strings-methods/exercise.js @@ -1,14 +1,9 @@ // Start by creating a variable `message` let name = "Busra"; let nameLength = name.length; -console.log(nameLength); - -let name1 = ' Busra ' let messageStart = 'My name is '; let messageEnd = " characters long"; let message = messageStart + name + ' and '+ messageStart.toLocaleLowerCase() + nameLength + messageEnd; -let messageTrimmed = messageStart + name1.trim() + ' and '+ messageStart.toLocaleLowerCase() + nameLength + messageEnd; console.log(message); -console.log(messageTrimmed); \ No newline at end of file diff --git a/exercises/F-strings-methods/exercise2.js b/exercises/F-strings-methods/exercise2.js index b4b46943d..ba4307da1 100644 --- a/exercises/F-strings-methods/exercise2.js +++ b/exercises/F-strings-methods/exercise2.js @@ -1,3 +1,8 @@ -const name = " Daniel "; +let name = ' Busra ' +let nameLength = name.trim().length; +let messageEnd = " characters long"; -console.log(message); +let messageStart = 'My name is '; +let messageTrimmed = messageStart + name.trim() + ' and '+ messageStart.toLocaleLowerCase() + nameLength + messageEnd; + +console.log(messageTrimmed); diff --git a/exercises/I-floats/exercise.js b/exercises/I-floats/exercise.js index dd8a01406..33b284b6c 100644 --- a/exercises/I-floats/exercise.js +++ b/exercises/I-floats/exercise.js @@ -2,11 +2,11 @@ let numberOfStudents = 15; let numberOfMentors = 8; let studentsText = 'Percentage students: ' -let percentageStudents = (15 / 23) * 100; +let percentageStudents = (numberOfStudents / (numberOfStudents + numberOfMentors)) * 100; let roughPercentageStudents = Math.round(percentageStudents) + '%'; console.log(studentsText + roughPercentageStudents); let mentorsText = 'Percentage mentors: ' -let percentageMentors = (8 / 23) * 100; +let percentageMentors = (numberOfMentors / (numberOfStudents + numberOfMentors)) * 100; let roughPercentageMentors = Math.round (percentageMentors) + '%'; console.log(mentorsText + roughPercentageMentors); \ No newline at end of file