From 19b917e344724df72e961f38d1f0cfea993dd0fe Mon Sep 17 00:00:00 2001 From: zhkvivan Date: Thu, 1 Jul 2021 17:48:26 +0100 Subject: [PATCH 1/4] exercises are done --- exercises/B-hello-world/exercise.js | 2 +- exercises/C-variables/exercise.js | 4 +++- exercises/D-strings/exercise.js | 2 ++ exercises/E-strings-concatenation/exercise.js | 4 ++++ exercises/F-strings-methods/exercise.js | 3 +++ exercises/F-strings-methods/exercise2.js | 4 +++- exercises/G-numbers/README.md | 2 +- exercises/G-numbers/exercise.js | 9 +++++++++ exercises/I-floats/exercise.js | 7 +++++++ 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 | 6 +++++- exercises/K-functions-parameters/exercise5.js | 3 +++ exercises/L-functions-nested/exercise.js | 10 ++++++++++ 17 files changed, 61 insertions(+), 6 deletions(-) diff --git a/exercises/B-hello-world/exercise.js b/exercises/B-hello-world/exercise.js index b179ee953..689b03943 100644 --- a/exercises/B-hello-world/exercise.js +++ b/exercises/B-hello-world/exercise.js @@ -1 +1 @@ -console.log("Hello world"); +console.log(66); diff --git a/exercises/C-variables/exercise.js b/exercises/C-variables/exercise.js index a6bbb9786..a768c7dd8 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..853504e66 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'; 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..2ab18425b 100644 --- a/exercises/E-strings-concatenation/exercise.js +++ b/exercises/E-strings-concatenation/exercise.js @@ -1,3 +1,7 @@ // Start by creating a variable `message` +let greetingStart = 'Hello, my name is '; +let name = 'Ivan'; +let message = greetingStart + name; + console.log(message); diff --git a/exercises/F-strings-methods/exercise.js b/exercises/F-strings-methods/exercise.js index 2cffa6a81..59309eb32 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 = 'Ivan'; +let nameLength = name.length; +let message = 'My name is ' + name + ' and my name is '+ name.length + ' characters long'; console.log(message); diff --git a/exercises/F-strings-methods/exercise2.js b/exercises/F-strings-methods/exercise2.js index b4b46943d..f7478c0fc 100644 --- a/exercises/F-strings-methods/exercise2.js +++ b/exercises/F-strings-methods/exercise2.js @@ -1,3 +1,5 @@ const name = " Daniel "; - +let newName = name.trim(); +let nameLength = newName.length; +let message = 'My name is ' + newName + ' and my name is '+ newName.length + ' characters long'; console.log(message); diff --git a/exercises/G-numbers/README.md b/exercises/G-numbers/README.md index 76a79dab2..6775ad18f 100644 --- a/exercises/G-numbers/README.md +++ b/exercises/G-numbers/README.md @@ -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..fae2b566e 100644 --- a/exercises/G-numbers/exercise.js +++ b/exercises/G-numbers/exercise.js @@ -1 +1,10 @@ // Start by creating a variables `numberOfStudents` and `numberOfMentors` + +let numberOfStudents = 30; +let numberOfMentors = 10; +let numberTotal = numberOfStudents+numberOfMentors; + +console.log('Number of students: ' + numberOfStudents); +console.log('Number of mentors: ' + numberOfMentors); +console.log('Total number of students and mentors: ' + numberTotal); + diff --git a/exercises/I-floats/exercise.js b/exercises/I-floats/exercise.js index a5bbcd852..4102fd30a 100644 --- a/exercises/I-floats/exercise.js +++ b/exercises/I-floats/exercise.js @@ -1,2 +1,9 @@ var numberOfStudents = 15; var numberOfMentors = 8; + +let percentOfStudents = numberOfStudents * 100 / (numberOfStudents + numberOfMentors); + +let percentOfMentors = numberOfMentors * 100 / (numberOfStudents + numberOfMentors); + +console.log('Percentage students: ' + Math.round(percentOfStudents)+ '%'); +console.log('Percentage mentors: ' + Math.round(percentOfMentors)+ '%'); diff --git a/exercises/J-functions/exercise.js b/exercises/J-functions/exercise.js index 0ae5850e5..0fc4c3655 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..468d45596 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..ea9d942d4 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(num1, num2) { + return num1 / num2; +} var result = divide(3, 4); diff --git a/exercises/K-functions-parameters/exercise3.js b/exercises/K-functions-parameters/exercise3.js index 537e9f4ec..46d38ee88 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..f3d8dfe3b 100644 --- a/exercises/K-functions-parameters/exercise4.js +++ b/exercises/K-functions-parameters/exercise4.js @@ -1,5 +1,9 @@ // Declare your function first - +function addnig(num1, num2) { + return num1 + num2; +} // Call the function and assign to a variable `sum` +let sum = addnig(13, 124); + console.log(sum); diff --git a/exercises/K-functions-parameters/exercise5.js b/exercises/K-functions-parameters/exercise5.js index 7c5bcd605..93fd044c9 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..4113e4a30 100644 --- a/exercises/L-functions-nested/exercise.js +++ b/exercises/L-functions-nested/exercise.js @@ -3,3 +3,13 @@ var mentor2 = "Irina"; var mentor3 = "Mimi"; var mentor4 = "Rob"; var mentor5 = "Yohannes"; + +function shoutGreeting(name) { + return 'HELLO ' + name.toUpperCase(); +} + +console.log(shoutGreeting(mentor1)); +console.log(shoutGreeting(mentor2)); +console.log(shoutGreeting(mentor3)); +console.log(shoutGreeting(mentor4)); +console.log(shoutGreeting(mentor5)); \ No newline at end of file From 5e2f162b65a4027b8f124dec18cde7e9b772570f Mon Sep 17 00:00:00 2001 From: zhkvivan Date: Sat, 3 Jul 2021 07:59:03 +0100 Subject: [PATCH 2/4] mandatory 1 done --- mandatory/1-syntax-errors.js | 12 ++++++------ mandatory/2-logic-error.js | 8 ++++---- package.json | 4 +++- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/mandatory/1-syntax-errors.js b/mandatory/1-syntax-errors.js index a10cc9ac2..8016c1c1e 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"; + let total = a + b; + return "The total is " + total; } /* diff --git a/mandatory/2-logic-error.js b/mandatory/2-logic-error.js index 9cca7603b..095dfc684 100644 --- a/mandatory/2-logic-error.js +++ b/mandatory/2-logic-error.js @@ -1,16 +1,16 @@ // 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/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 b52550bdb2b59aa7ee051d31487a43f2bf03fb40 Mon Sep 17 00:00:00 2001 From: zhkvivan Date: Sat, 3 Jul 2021 08:02:53 +0100 Subject: [PATCH 3/4] mandatory 2 done --- mandatory/2-logic-error.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mandatory/2-logic-error.js b/mandatory/2-logic-error.js index 095dfc684..4902e77f2 100644 --- a/mandatory/2-logic-error.js +++ b/mandatory/2-logic-error.js @@ -5,7 +5,7 @@ function trimWord(word) { } function getStringLength(word) { - return word.length(); + return word.length; } function multiply(a, b, c) { From b228a7c2054b19a1779945a46df6306827341944 Mon Sep 17 00:00:00 2001 From: zhkvivan Date: Sat, 3 Jul 2021 08:10:02 +0100 Subject: [PATCH 4/4] mandatory 3 done --- mandatory/3-function-output.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mandatory/3-function-output.js b/mandatory/3-function-output.js index 5a953ba60..0373e6d8f 100644 --- a/mandatory/3-function-output.js +++ b/mandatory/3-function-output.js @@ -2,15 +2,18 @@ function getRandomNumber() { return Math.random() * 10; } +// This function returns a random number multiplied by 10 // Add comments to explain what this function does. You're meant to use Google! function combine2Words(word1, word2) { return word1.concat(word2); } +// This function combines two words into one 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.concat(' ',secondWord, ' ', thirdWord); } /*