From c7edb5d5821d9b5ea044f94b40bb07bb154ed629 Mon Sep 17 00:00:00 2001 From: Tersia Koetzee Date: Fri, 1 Jul 2022 21:21:18 +0200 Subject: [PATCH 1/2] completed exercises --- exercises/B-hello-world/exercise.js | 4 +++- exercises/C-variables/exercise.js | 4 +++- exercises/D-strings/exercise.js | 3 +++ exercises/E-strings-concatenation/exercise.js | 8 +++++++- exercises/F-strings-methods/exercise.js | 16 +++++++++++++++- exercises/F-strings-methods/exercise2.js | 18 ++++++++++++++++-- exercises/G-numbers/exercise.js | 11 +++++++++++ exercises/I-floats/exercise.js | 13 +++++++++++++ exercises/J-functions/exercise.js | 1 + exercises/J-functions/exercise2.js | 1 + exercises/K-functions-parameters/README.md | 1 + exercises/K-functions-parameters/exercise.js | 4 +++- exercises/K-functions-parameters/exercise2.js | 4 +++- exercises/K-functions-parameters/exercise3.js | 7 ++++++- exercises/K-functions-parameters/exercise4.js | 5 ++++- exercises/K-functions-parameters/exercise5.js | 7 ++++++- exercises/L-functions-nested/README.md | 1 + exercises/L-functions-nested/exercise.js | 14 ++++++++++++++ mandatory/1-syntax-errors.js | 15 +++++++++------ mandatory/2-logic-error.js | 8 ++++---- mandatory/3-function-output.js | 5 +++++ package.json | 12 +++++++++--- 22 files changed, 138 insertions(+), 24 deletions(-) diff --git a/exercises/B-hello-world/exercise.js b/exercises/B-hello-world/exercise.js index b179ee953..c0b117af9 100644 --- a/exercises/B-hello-world/exercise.js +++ b/exercises/B-hello-world/exercise.js @@ -1 +1,3 @@ -console.log("Hello world"); +console.log("Hello world I am relearning Javascript :)"); +console.log(7); +console.log("this is another log"); \ No newline at end of file diff --git a/exercises/C-variables/exercise.js b/exercises/C-variables/exercise.js index a6bbb9786..ff52bf2a0 100644 --- a/exercises/C-variables/exercise.js +++ b/exercises/C-variables/exercise.js @@ -1,3 +1,5 @@ // Start by creating a variable `greeting` - +var greeting = "Hello Tersia how are you today?" +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..3772ea23d 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 = "This is a string"; +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..c983ea1f9 100644 --- a/exercises/E-strings-concatenation/exercise.js +++ b/exercises/E-strings-concatenation/exercise.js @@ -1,3 +1,9 @@ // Start by creating a variable `message` +var greetingStart = "Hello, my name is "; +var names = "Tersia"; + +var greeting = greetingStart + names ; + +console.log(greeting); + -console.log(message); diff --git a/exercises/F-strings-methods/exercise.js b/exercises/F-strings-methods/exercise.js index 2cffa6a81..b7153ed29 100644 --- a/exercises/F-strings-methods/exercise.js +++ b/exercises/F-strings-methods/exercise.js @@ -1,3 +1,17 @@ // Start by creating a variable `message` +var greetingStart = "Hello, my name is "; +var names = "Daniel and my name is"; -console.log(message); +var greeting = greetingStart + names ; + +var names = "Daniel"; +var nameLength = names.length; + +var nameLen = " characters long" + +var fullGreeting = greetingStart + names + nameLength + nameLen + + console.log(greeting); + console.log(nameLength); + console.log(fullGreeting); +// My name is Daniel and my name is 6 characters long diff --git a/exercises/F-strings-methods/exercise2.js b/exercises/F-strings-methods/exercise2.js index b4b46943d..ce6ad1c03 100644 --- a/exercises/F-strings-methods/exercise2.js +++ b/exercises/F-strings-methods/exercise2.js @@ -1,3 +1,17 @@ -const name = " Daniel "; +var greetingStart = "Hello, my name is "; +var names = "Tersia and my name is"; + +var greeting = greetingStart + names ; + +var names = "Tersia "; +var nameLength = names.length; + +var nameLen = " characters long." + +var fullGreeting = greetingStart + names + nameLength + nameLen + +// console.log(greeting); +// console.log(nameLength); + console.log(fullGreeting.trim()); + -console.log(message); diff --git a/exercises/G-numbers/exercise.js b/exercises/G-numbers/exercise.js index 49e7bc00b..f055a3d70 100644 --- a/exercises/G-numbers/exercise.js +++ b/exercises/G-numbers/exercise.js @@ -1 +1,12 @@ // Start by creating a variables `numberOfStudents` and `numberOfMentors` +var studentNum = "Number of students: " +var mentorsNum = "Number of mentors: " +var people = "Total number of students and mentors:" + +var students = 15; +var mentors = 8; +var total = 15 + 8; + +console.log(studentNum + students); +console.log(mentorsNum + mentors); +console.log(people + total); \ No newline at end of file diff --git a/exercises/I-floats/exercise.js b/exercises/I-floats/exercise.js index a5bbcd852..d5b3fe0c5 100644 --- a/exercises/I-floats/exercise.js +++ b/exercises/I-floats/exercise.js @@ -1,2 +1,15 @@ var numberOfStudents = 15; var numberOfMentors = 8; +var percentage = numberOfStudents + numberOfMentors; + +let percentageOfStudents = `Percentage students: ${numberOfStudents / percentage * 100} `; +let percentageOfMentors = `Percentage mentors: ${numberOfMentors / percentage * 100}`; + +let students = 65.21739130434783 +let studentpercent = Math.round(students) +let mentors = 34.78260869565217 +let mentorspercent = Math.round(mentors) + + +console.log(studentpercent); +console.log(mentorspercent); diff --git a/exercises/J-functions/exercise.js b/exercises/J-functions/exercise.js index 0ae5850e5..138e3180a 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..d29e195d9 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/README.md b/exercises/K-functions-parameters/README.md index 1614e221b..a981f49c7 100644 --- a/exercises/K-functions-parameters/README.md +++ b/exercises/K-functions-parameters/README.md @@ -65,6 +65,7 @@ Hello, my name is Daniel ## Expected result + ``` Hello, my name is Daniel and I'm 30 years old ``` diff --git a/exercises/K-functions-parameters/exercise.js b/exercises/K-functions-parameters/exercise.js index 8d5db5e69..2fcca0787 100644 --- a/exercises/K-functions-parameters/exercise.js +++ b/exercises/K-functions-parameters/exercise.js @@ -1,8 +1,10 @@ // Complete the function so that it takes input parameters -function multiply() { +function multiply(dig, num) { // Calculate the result of the function and return it + return dig * num; } + // Assign the result of calling the function the variable `result` var result = multiply(3, 4); diff --git a/exercises/K-functions-parameters/exercise2.js b/exercises/K-functions-parameters/exercise2.js index db7a8904b..812583523 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..92de81a11 100644 --- a/exercises/K-functions-parameters/exercise3.js +++ b/exercises/K-functions-parameters/exercise3.js @@ -1,5 +1,10 @@ // Write your function here -var greeting = createGreeting("Daniel"); +var greeting = "Hello my name is, Daniel" + +function createGreeting(){ +return greeting ; +} + console.log(greeting); diff --git a/exercises/K-functions-parameters/exercise4.js b/exercises/K-functions-parameters/exercise4.js index 7ab44589e..7428db286 100644 --- a/exercises/K-functions-parameters/exercise4.js +++ b/exercises/K-functions-parameters/exercise4.js @@ -1,5 +1,8 @@ // Declare your function first - +function addnumbers (numberone, numbertwo){ +return numberone + numbertwo +} // Call the function and assign to a variable `sum` +var 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..ef6fe2d57 100644 --- a/exercises/K-functions-parameters/exercise5.js +++ b/exercises/K-functions-parameters/exercise5.js @@ -1,5 +1,10 @@ // Declare your function here +const string = "Hello, my name is Daniel and I'm "; +const stringtwo = " years old"; -const greeting = createLongGreeting("Daniel", 30); +function introduction(age){ + return string + age + stringtwo; +} +const greeting = introduction(30); console.log(greeting); diff --git a/exercises/L-functions-nested/README.md b/exercises/L-functions-nested/README.md index 1c4ae9c8a..12eae424d 100644 --- a/exercises/L-functions-nested/README.md +++ b/exercises/L-functions-nested/README.md @@ -4,6 +4,7 @@ Functions are very powerful. - You can use variables inside of functions. - You can call other functions inside of functions! + ```js function getAgeInDays(age) { return age * 365; diff --git a/exercises/L-functions-nested/exercise.js b/exercises/L-functions-nested/exercise.js index a5d377442..c878f520b 100644 --- a/exercises/L-functions-nested/exercise.js +++ b/exercises/L-functions-nested/exercise.js @@ -3,3 +3,17 @@ var mentor2 = "Irina"; var mentor3 = "Mimi"; var mentor4 = "Rob"; var mentor5 = "Yohannes"; + +let name1 = mentor1.toUpperCase(); +let name2 = mentor2.toUpperCase(); +let name3 = mentor3.toUpperCase(); +let name4 = mentor4.toUpperCase(); +let name5 = mentor5.toUpperCase(); + +function shouty(){ +let test = {hi: name1, hi: name2, name3, name4, name5} +return test +} + +let test1 = shouty() +console.log(test1.name3); diff --git a/mandatory/1-syntax-errors.js b/mandatory/1-syntax-errors.js index a10cc9ac2..570a0845e 100644 --- a/mandatory/1-syntax-errors.js +++ b/mandatory/1-syntax-errors.js @@ -1,18 +1,21 @@ // 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; +function getTotal(a, b){ + var total = a + b; - return "The total is total"; + 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 9cca7603b..aab927c31 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/mandatory/3-function-output.js b/mandatory/3-function-output.js index 5a953ba60..0b4377444 100644 --- a/mandatory/3-function-output.js +++ b/mandatory/3-function-output.js @@ -1,9 +1,12 @@ // Add comments to explain what this function does. You're meant to use Google! +// method to create a function that will return a random integer between 0 and 9 values function getRandomNumber() { return Math.random() * 10; } + // Add comments to explain what this function does. You're meant to use Google! +// This function concatenates two strings together function combine2Words(word1, word2) { return word1.concat(word2); } @@ -11,6 +14,8 @@ function combine2Words(word1, 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.concat("", secondWord ," ",thirdWord) } /* 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 c5832fbee4be8b29376bce64605c1e1add9715ea Mon Sep 17 00:00:00 2001 From: Tersia Koetzee Date: Fri, 1 Jul 2022 21:33:26 +0200 Subject: [PATCH 2/2] completed exercises