From 098a5aeebe1ab272e3815f94b902563f2bb4907e Mon Sep 17 00:00:00 2001 From: Ying X Date: Thu, 24 Nov 2022 19:55:14 +0000 Subject: [PATCH 1/6] fixed syntax errors 1 --- mandatory/1-syntax-errors.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mandatory/1-syntax-errors.js b/mandatory/1-syntax-errors.js index a10cc9ac2..34c89431b 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"; + return "Hello, my name is " + name + " and I am " + age + " years old"; function getTotal(a, b) { - total = a ++ b; + total = a + b; - return "The total is total"; + return "The total is " + total; } /* From e30ccb06f3c9e7bc3b0cbf6535b1db1145905526 Mon Sep 17 00:00:00 2001 From: Ying X Date: Thu, 24 Nov 2022 20:04:57 +0000 Subject: [PATCH 2/6] fixed logic error --- mandatory/2-logic-error.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mandatory/2-logic-error.js b/mandatory/2-logic-error.js index 9cca7603b..ef14abdf9 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; + } /* From c31187447add3d804c03a6186c21be03d21ff84b Mon Sep 17 00:00:00 2001 From: Ying X Date: Thu, 24 Nov 2022 20:17:26 +0000 Subject: [PATCH 3/6] function output completed --- mandatory/3-function-output.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/mandatory/3-function-output.js b/mandatory/3-function-output.js index 5a953ba60..c94f64e12 100644 --- a/mandatory/3-function-output.js +++ b/mandatory/3-function-output.js @@ -3,14 +3,24 @@ function getRandomNumber() { return Math.random() * 10; } +// The Math object in JavaScript is a built-in object that has properties and methods for performing mathematical calculations. +// A common use of the Math object is to create a random number using the random() method. + // Add comments to explain what this function does. You're meant to use Google! function combine2Words(word1, word2) { return word1.concat(word2); } +//The concat() method joins two or more strings. + +//The concat() method does not change the existing strings. + +//The concat() method returns a new string. + 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) } /* From 4abaeabd6b95aee9b98fd8da581368ecd2950671 Mon Sep 17 00:00:00 2001 From: Ying X Date: Thu, 24 Nov 2022 20:32:58 +0000 Subject: [PATCH 4/6] completed tax --- mandatory/4-tax.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/mandatory/4-tax.js b/mandatory/4-tax.js index ba77c7ae2..6e9de3c5e 100644 --- a/mandatory/4-tax.js +++ b/mandatory/4-tax.js @@ -5,7 +5,10 @@ Sales tax is 20% of the price of the product. */ -function calculateSalesTax() {} +function calculateSalesTax(product) { + let incSalesTax=product*1.2; + return incSalesTax; +} /* CURRENCY FORMATTING @@ -17,7 +20,11 @@ function calculateSalesTax() {} Remember that the prices must include the sales tax (hint: you already wrote a function for this!) */ -function addTaxAndFormatCurrency() {} +function addTaxAndFormatCurrency(currency) { + let first=calculateSalesTax(currency); + let second=first.toFixed(2); + return `£${second}`; +} /* =================================================== From 60fa6d6db623c27ac759f036d47268f14e49205a Mon Sep 17 00:00:00 2001 From: Ying X Date: Fri, 25 Nov 2022 22:34:10 +0000 Subject: [PATCH 5/6] exercises completed --- exercises/B-hello-world/exercise.js | 6 ++++++ exercises/C-variables/exercise.js | 4 +++- exercises/D-strings/exercise.js | 6 ++++-- exercises/E-strings-concatenation/exercise.js | 5 +++-- exercises/F-strings-methods/exercise.js | 4 +++- exercises/F-strings-methods/exercise2.js | 3 ++- exercises/G-numbers/exercise.js | 4 ++++ exercises/I-floats/exercise.js | 7 +++++++ exercises/J-functions/exercise.js | 1 + exercises/J-functions/exercise2.js | 6 ++++-- exercises/K-functions-parameters/exercise.js | 3 ++- exercises/K-functions-parameters/exercise2.js | 4 +++- exercises/K-functions-parameters/exercise3.js | 4 +++- exercises/K-functions-parameters/exercise4.js | 6 ++++-- exercises/K-functions-parameters/exercise5.js | 5 +++++ exercises/L-functions-nested/exercise.js | 15 ++++++++++++++- 16 files changed, 68 insertions(+), 15 deletions(-) diff --git a/exercises/B-hello-world/exercise.js b/exercises/B-hello-world/exercise.js index b179ee953..74843b2f3 100644 --- a/exercises/B-hello-world/exercise.js +++ b/exercises/B-hello-world/exercise.js @@ -1 +1,7 @@ console.log("Hello world"); +console.log("Hello world. I just started learning JavaScript") +console.log("what happens when i get rid of the quote marks?") +console.log("syntax error will occur") +console.log(7) +console.log('it logs the number') + diff --git a/exercises/C-variables/exercise.js b/exercises/C-variables/exercise.js index a6bbb9786..bb50329e6 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..f8b5d5757 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='lexi was doing the exercises' +let type=typeof message; +console.log(message) +console.log(type); diff --git a/exercises/E-strings-concatenation/exercise.js b/exercises/E-strings-concatenation/exercise.js index 2cffa6a81..488d7b85d 100644 --- a/exercises/E-strings-concatenation/exercise.js +++ b/exercises/E-strings-concatenation/exercise.js @@ -1,3 +1,4 @@ // Start by creating a variable `message` - -console.log(message); +let firstName='lexi ' +let lastName='Xing' +console.log(firstName + lastName); diff --git a/exercises/F-strings-methods/exercise.js b/exercises/F-strings-methods/exercise.js index 2cffa6a81..0be2e4992 100644 --- a/exercises/F-strings-methods/exercise.js +++ b/exercises/F-strings-methods/exercise.js @@ -1,3 +1,5 @@ // Start by creating a variable `message` +let name ="lexi"; +let nameLength = name.length; -console.log(message); +console.log(name + nameLength); diff --git a/exercises/F-strings-methods/exercise2.js b/exercises/F-strings-methods/exercise2.js index b4b46943d..69f261f15 100644 --- a/exercises/F-strings-methods/exercise2.js +++ b/exercises/F-strings-methods/exercise2.js @@ -1,3 +1,4 @@ const name = " Daniel "; +const nameTrim=name.trim(); -console.log(message); +console.log(nameTrim); diff --git a/exercises/G-numbers/exercise.js b/exercises/G-numbers/exercise.js index 49e7bc00b..ad1ef74e5 100644 --- a/exercises/G-numbers/exercise.js +++ b/exercises/G-numbers/exercise.js @@ -1 +1,5 @@ // Start by creating a variables `numberOfStudents` and `numberOfMentors` +let numberOfStudents=15; +let numberOfMentors=8; +let total=numberOfMentors + numberOfStudents; +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..945db3616 100644 --- a/exercises/I-floats/exercise.js +++ b/exercises/I-floats/exercise.js @@ -1,2 +1,9 @@ var numberOfStudents = 15; var numberOfMentors = 8; +var total=numberOfMentors + numberOfStudents; +var numberOfMen=Math.round((numberOfMentors/total)*100); +let perOfMen=numberOfMen + `%`; +var numberOfStu=Math.round((numberOfStudents/total)*100); +let perOfStu=numberOfStu + `%`; +console.log(perOfMen); +console.log(perOfStu); diff --git a/exercises/J-functions/exercise.js b/exercises/J-functions/exercise.js index 0ae5850e5..27ad56963 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..165621add 100644 --- a/exercises/J-functions/exercise2.js +++ b/exercises/J-functions/exercise2.js @@ -1,7 +1,9 @@ function triple(number) { // complete function here + return number*number*number } -var result = triple(12); - +var result1 = triple(6); +var result = triple(2); +console.log(result1); console.log(result); diff --git a/exercises/K-functions-parameters/exercise.js b/exercises/K-functions-parameters/exercise.js index 8d5db5e69..f19e3b156 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(a,b) { // Calculate the result of the function and return it + return a*b } // 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..dd2393028 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(a,b) { + return a/b +} 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..4c41baba6 100644 --- a/exercises/K-functions-parameters/exercise3.js +++ b/exercises/K-functions-parameters/exercise3.js @@ -1,5 +1,7 @@ // Write your function here - +function createGreeting(name){ + return ('nice to meet you ' + name) +} 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..989d511df 100644 --- a/exercises/K-functions-parameters/exercise4.js +++ b/exercises/K-functions-parameters/exercise4.js @@ -1,5 +1,7 @@ // Declare your function first - +function summed(a,b) { + return a+b +} // Call the function and assign to a variable `sum` - +let sum = summed(13 + 24) console.log(sum); diff --git a/exercises/K-functions-parameters/exercise5.js b/exercises/K-functions-parameters/exercise5.js index 7c5bcd605..9a467f7a9 100644 --- a/exercises/K-functions-parameters/exercise5.js +++ b/exercises/K-functions-parameters/exercise5.js @@ -1,4 +1,9 @@ // 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..ad50a6a8a 100644 --- a/exercises/L-functions-nested/exercise.js +++ b/exercises/L-functions-nested/exercise.js @@ -1,5 +1,18 @@ -var mentor1 = "Daniel"; +var mentor1 = "Daniel! "; var mentor2 = "Irina"; var mentor3 = "Mimi"; var mentor4 = "Rob"; var mentor5 = "Yohannes"; +function nameUpperCase (name) { + return name.toUpperCase(); +} + +function greetingMentors (name) { + return `hello ${nameUpperCase(name)}`; +} + +console.log(greetingMentors(mentor1)); +console.log(greetingMentors(mentor2)); +console.log(greetingMentors(mentor3)); +console.log(greetingMentors(mentor4)); +console.log(greetingMentors(mentor5)); \ No newline at end of file From 29778576eefa0ac912a7d04092a87cb22f4692d4 Mon Sep 17 00:00:00 2001 From: Ying X Date: Fri, 2 Dec 2022 06:47:09 +0000 Subject: [PATCH 6/6] fixed J-functions exercises 2 --- .DS_Store | Bin 0 -> 6148 bytes exercises/J-functions/exercise2.js | 3 +- exercises/L-functions-nested/even.js | 60 +++++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 .DS_Store create mode 100644 exercises/L-functions-nested/even.js diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..882e59b1ab4850506ea9f2dab339122fbb38dffa GIT binary patch literal 6148 zcmeHKPfNov6i>FP=|tQ?P;a?-+hN^s;6W&J9=r(^J*aH08?G>0Sv#xFNk4~vBfo%O z$M=$KI5tm$$aoK4elPD&LVhVp!x-a@VaH~y#26Exh&c=Ld}E(QQGaTC{&~<%Tcxd|C``N{><(0M(CI?T)kP3?qO=hW!%nQm zadkilOIWSa?r2o4*2>bZ*T!WzvMYAAEcfdNW17H8NQ|$l% literal 0 HcmV?d00001 diff --git a/exercises/J-functions/exercise2.js b/exercises/J-functions/exercise2.js index 165621add..7c859fdbe 100644 --- a/exercises/J-functions/exercise2.js +++ b/exercises/J-functions/exercise2.js @@ -1,9 +1,10 @@ function triple(number) { // complete function here - return number*number*number + return number * 3; } var result1 = triple(6); var result = triple(2); console.log(result1); console.log(result); + diff --git a/exercises/L-functions-nested/even.js b/exercises/L-functions-nested/even.js new file mode 100644 index 000000000..6a4c8972e --- /dev/null +++ b/exercises/L-functions-nested/even.js @@ -0,0 +1,60 @@ + + + +/*function moodChecker(mood) { + if (mood === "Happy") { + return 'good job, you are doing great'; + + } else if (mood === "sad") { + return "every cloud has a silver lining"; + } else if (typeof mood === "number") { + return "beep beep boop"; + } else { + return "i'm sorry, i'm still learning about feelings" + } +} +*/ + + +// console.log(moodChecker("hmm")); + +// && and +// || or +// ! not + +function checkUsername(userName, userType) { + if (userType === "admin" || userType === "manager") { + return "username valid" + } + else if (userName(0) === userName(0).toUpperCase() && userName.length >5 + && userName <10 ) { + return "username valid"; + } else { + return "username invalid"; + } +} + +console.log(checkUsername("lexi", "admin")); + +const fruits = ['banana', 'apple', 'strawberry', 'kiwi', 'fig', 'orange']; +console.log(fruits[2], fruits[3]); + +/*function lastTask (tasks) { + console.log(tasks[2]); + console.log(tasks.length); + return `don't forget to ${tasks[2].toUpperCase()}` +} + + + +let tasks =['do the dishes', 'take out garbage', 'practice coding']; +console.log(lastTask(tasks)); */ + +function randomTask(tasks) { + +} + +let tasks = ['do the dishes', 'take out garbage', +'practice coding', 'clean house']; +console.log(randomTask['do the dishes', 'take out garbage', +'practice coding', 'clean house']); \ No newline at end of file