From 830c9837a2b3513e1bf42654fd2325389115b4cd Mon Sep 17 00:00:00 2001 From: moniqueking57 <65675759+moniqueking57@users.noreply.github.com> Date: Tue, 8 Dec 2020 10:16:29 +0000 Subject: [PATCH 1/6] Done 1,2,3 working on 4 --- mandatory/1-syntax-errors.js | 11 ++++++----- mandatory/2-logic-error.js | 8 ++++---- mandatory/3-function-output.js | 7 +++++-- mandatory/4-tax.js | 8 ++++++-- 4 files changed, 21 insertions(+), 13 deletions(-) diff --git a/mandatory/1-syntax-errors.js b/mandatory/1-syntax-errors.js index 0a21afd1b..f397a1ac3 100644 --- a/mandatory/1-syntax-errors.js +++ b/mandatory/1-syntax-errors.js @@ -1,16 +1,17 @@ // 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; + let 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 3c578ad87..dd10217c9 100644 --- a/mandatory/2-logic-error.js +++ b/mandatory/2-logic-error.js @@ -1,18 +1,18 @@ // 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 getWordLength(word) { - return "word".length(); + return word.length; } function multiply(a, b, c) { - a * b * c; - return; + return a * b * c; } + /* =================================================== ======= TESTS - DO NOT MODIFY BELOW THIS LINE ===== diff --git a/mandatory/3-function-output.js b/mandatory/3-function-output.js index c9221a200..1f93cc0c3 100644 --- a/mandatory/3-function-output.js +++ b/mandatory/3-function-output.js @@ -1,14 +1,17 @@ -// Add comments to explain what this function does. You're meant to use Google! +// This function is getting a random number to be defined later to be times by 10. function getNumber() { return Math.random() * 10; } -// Add comments to explain what this function does. You're meant to use Google! + + +// This function is concatenating word 1 and word 2. The words will be defined later. function s(w1, w2) { return w1.concat(w2); } function concatenate(firstWord, secondWord, thirdWord) { + return firstWord.concat(" " + 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. } diff --git a/mandatory/4-tax.js b/mandatory/4-tax.js index c9e41c691..c75de4f10 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(a) { + return a+(a*0.2) +} /* CURRENCY FORMATTING @@ -17,7 +19,9 @@ function calculateSalesTax() {} Remember that the prices must include the sales tax (hint: you already wrote a function for this!) */ -function addTaxAndFormatCurrency() {} +function addTaxAndFormatCurrency(b) { + return b + calculateSalesTax +} /* =================================================== From aa69279ba7c95b0fcff1023f389879c2c5186a4f Mon Sep 17 00:00:00 2001 From: moniqueking57 <65675759+moniqueking57@users.noreply.github.com> Date: Tue, 8 Dec 2020 22:32:25 +0000 Subject: [PATCH 2/6] task 4 finished --- mandatory/4-tax.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/mandatory/4-tax.js b/mandatory/4-tax.js index c75de4f10..6877c9cf4 100644 --- a/mandatory/4-tax.js +++ b/mandatory/4-tax.js @@ -6,9 +6,10 @@ */ function calculateSalesTax(a) { - return a+(a*0.2) + return a+a*0.2 } + /* CURRENCY FORMATTING =================== @@ -19,10 +20,12 @@ function calculateSalesTax(a) { Remember that the prices must include the sales tax (hint: you already wrote a function for this!) */ -function addTaxAndFormatCurrency(b) { - return b + calculateSalesTax + +function addTaxAndFormatCurrency(a) { + return "£" + calculateSalesTax(a).toFixed(2); } + /* =================================================== ======= TESTS - DO NOT MODIFY BELOW THIS LINE ===== From 73f37365334cdf0a263a68b13da0d6976963e903 Mon Sep 17 00:00:00 2001 From: moniqueking57 <65675759+moniqueking57@users.noreply.github.com> Date: Fri, 11 Dec 2020 12:54:49 +0000 Subject: [PATCH 3/6] Working through the exercises --- .DS_Store | Bin 0 -> 6148 bytes exercises/B-hello-world/exercise.js | 4 +++- 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..e1d92ff0725d4ee360f08c04ed6ea0d6e647088c GIT binary patch literal 6148 zcmeHK-EPw`82#LJkQ5;*gv4%;a>HFawHuqn1yTsDpb~?L6m|hDWeqi zo+p53K;k)g0-l8{IQ|)0(;)6DK>no9=Zo!Q$H%c96A|-9QJbhvL>63NwT7g`M7i(< ztLPjX$YdLb6jMe6%6iE{ZIfXXFbe!_3W&99W5vFK59!?c<%eOyLzIfG;VyjrhcrY) ztCEp}5%iL|nqLYvYjmHUfZw4WJwm)r#}v(T*o^|`Dm|dbv`0-^P0elv0E=CytSx&cAi#)t?#RI6KiQehp8OILlkD zZ>+LXUA=J8vT9cCa_yym#K(RfyL?S|9d+L|_;$?c6+!@0G&J)PRt z^_%TGy@TV^x083%_a8AV7{i7x?TW@T_=KQDoY(#^O?WCq5lkDC-j&n711ykx{@X@UJK!_6G+p(A79oD7OwI@(KW~B3l|_@xvfEjz(AG zOd(2OOi_V~%Jdb3DLV2UUC-4xQ>f^~^yP!;o|(R(FxflWcVu;9u0oR<1&jjo3aqHd zx;X#4zrX*_lgyJ*z$oxvDZr{7zvE#@`fObooH%P8_yJs)s5et6DM<8jECX>Aufe6E Z%n Date: Sat, 12 Dec 2020 10:07:42 +0000 Subject: [PATCH 4/6] more exercises comp --- exercises/C-variables/exercise.js | 4 +++- exercises/D-strings/exercise.js | 3 +++ exercises/E-strings-concatenation/exercise.js | 6 +++++- exercises/G-numbers/exercise.js | 8 ++++++++ 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/exercises/C-variables/exercise.js b/exercises/C-variables/exercise.js index a6bbb9786..03719cf97 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 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..6d44141d0 100644 --- a/exercises/D-strings/exercise.js +++ b/exercises/D-strings/exercise.js @@ -1,3 +1,6 @@ // Start by creating a variable `message` +let message = "Hola"; +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..b8ba4daaa 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` +var greet = "Hello, my name is "; +var name = "Monique"; -console.log(message); +var greeting = greet + name; + +console.log(greeting); diff --git a/exercises/G-numbers/exercise.js b/exercises/G-numbers/exercise.js index 49e7bc00b..b04c4de6b 100644 --- a/exercises/G-numbers/exercise.js +++ b/exercises/G-numbers/exercise.js @@ -1 +1,9 @@ // Start by creating a variables `numberOfStudents` and `numberOfMentors` +let numberOfStudents = 15; +let numberOfMentors = 3; + +let total = numberOfStudents + numberOfMentors; + +console.log(`Number of students: ${numberOfStudents}`); +console.log(`Number of mentors: ${numberOfMentors}`); +console.log(`Total no of s and m: ${total}`); \ No newline at end of file From 2b5f64189a0d2c96972f04366f5dcf2ae63f2031 Mon Sep 17 00:00:00 2001 From: moniqueking57 <65675759+moniqueking57@users.noreply.github.com> Date: Sat, 12 Dec 2020 20:57:58 +0000 Subject: [PATCH 5/6] exercises finished --- exercises/F-strings-methods/exercise.js | 5 ++- exercises/F-strings-methods/exercise2.js | 4 ++- exercises/I-floats/exercise.js | 10 ++++++ exercises/J-functions/exercise.js | 6 +++- exercises/J-functions/exercise2.js | 5 +-- exercises/K-functions-parameters/exercise.js | 6 ++-- exercises/K-functions-parameters/exercise2.js | 7 ++-- exercises/K-functions-parameters/exercise3.js | 6 ++-- exercises/K-functions-parameters/exercise4.js | 7 +++- exercises/K-functions-parameters/exercise5.js | 6 +++- exercises/L-functions-nested/exercise.js | 34 +++++++++++++++++++ 11 files changed, 82 insertions(+), 14 deletions(-) diff --git a/exercises/F-strings-methods/exercise.js b/exercises/F-strings-methods/exercise.js index 2cffa6a81..767f8dfc0 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 = "Monique"; +let nameLength = name.length; + +console.log(`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..3cf942bd4 100644 --- a/exercises/F-strings-methods/exercise2.js +++ b/exercises/F-strings-methods/exercise2.js @@ -1,3 +1,5 @@ const name = " Daniel "; +const addTrim = name.trim(); +const newNameLength = addTrim.length; -console.log(message); +console.log(`My name is ${addTrim} and my name is ${newNameLength} characters long`); \ No newline at end of file diff --git a/exercises/I-floats/exercise.js b/exercises/I-floats/exercise.js index a5bbcd852..df8b3ec43 100644 --- a/exercises/I-floats/exercise.js +++ b/exercises/I-floats/exercise.js @@ -1,2 +1,12 @@ var numberOfStudents = 15; var numberOfMentors = 8; + +var total = numberOfStudents + numberOfMentors; + +var convertStudents = numberOfStudents / total * 100; +var convertMentors = numberOfMentors / total * 100; +var percentageOfStudents = Math.round(convertStudents); +var percentageOfMentors = Math.round(convertMentors); + +console.log(`Percentage students: ${percentageOfStudents}%`); +console.log(`Percentage students: ${percentageOfMentors}%`); \ No newline at end of file diff --git a/exercises/J-functions/exercise.js b/exercises/J-functions/exercise.js index 0ae5850e5..5cf5635d5 100644 --- a/exercises/J-functions/exercise.js +++ b/exercises/J-functions/exercise.js @@ -1,7 +1,11 @@ function halve(number) { - // complete the function here + return number / 2;// complete the function here } var result = halve(12); +var result1 = halve(10); +var result2 = halve(9); console.log(result); +console.log(result1); +console.log(result2); \ No newline at end of file diff --git a/exercises/J-functions/exercise2.js b/exercises/J-functions/exercise2.js index 82ef5e780..946e2ba3a 100644 --- a/exercises/J-functions/exercise2.js +++ b/exercises/J-functions/exercise2.js @@ -1,7 +1,8 @@ + function triple(number) { - // complete function here + return number * 3// complete function here } var result = triple(12); -console.log(result); +console.log(result); \ No newline at end of file diff --git a/exercises/K-functions-parameters/exercise.js b/exercises/K-functions-parameters/exercise.js index 8d5db5e69..92cdc648d 100644 --- a/exercises/K-functions-parameters/exercise.js +++ b/exercises/K-functions-parameters/exercise.js @@ -1,9 +1,9 @@ // 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; // Calculate the result of the function and return it } // Assign the result of calling the function the variable `result` var result = multiply(3, 4); -console.log(result); +console.log(result); \ No newline at end of file diff --git a/exercises/K-functions-parameters/exercise2.js b/exercises/K-functions-parameters/exercise2.js index db7a8904b..5b917e0b9 100644 --- a/exercises/K-functions-parameters/exercise2.js +++ b/exercises/K-functions-parameters/exercise2.js @@ -1,5 +1,8 @@ -// Declare your function first + +function divide (num1, num2) { + return num1 / num2; +} // Declare your function first var result = divide(3, 4); -console.log(result); +console.log(result); \ No newline at end of file diff --git a/exercises/K-functions-parameters/exercise3.js b/exercises/K-functions-parameters/exercise3.js index 537e9f4ec..e0463d216 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 `Hello, my name is ${name}`; +} var greeting = createGreeting("Daniel"); -console.log(greeting); +console.log(greeting); \ No newline at end of file diff --git a/exercises/K-functions-parameters/exercise4.js b/exercises/K-functions-parameters/exercise4.js index 7ab44589e..34a566212 100644 --- a/exercises/K-functions-parameters/exercise4.js +++ b/exercises/K-functions-parameters/exercise4.js @@ -1,5 +1,10 @@ // Declare your function first +function add (num1, num2) { + return num1 + num2; +} // Call the function and assign to a variable `sum` -console.log(sum); +var sum = add (13, 124); + +console.log(sum); \ No newline at end of file diff --git a/exercises/K-functions-parameters/exercise5.js b/exercises/K-functions-parameters/exercise5.js index 7c5bcd605..e8b09eeb2 100644 --- a/exercises/K-functions-parameters/exercise5.js +++ b/exercises/K-functions-parameters/exercise5.js @@ -1,5 +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); -console.log(greeting); +console.log(greeting); \ No newline at end of file diff --git a/exercises/L-functions-nested/exercise.js b/exercises/L-functions-nested/exercise.js index a5d377442..cdc7bc3e8 100644 --- a/exercises/L-functions-nested/exercise.js +++ b/exercises/L-functions-nested/exercise.js @@ -1,5 +1,39 @@ +function groupPercentage(num1, num2){ + let totalInGroup = num1 + num2; + return calculatePercentage = Math.round((num1 / totalInGroup) * 100); +} + +function message(numberOfStudents, numberOfMentors){ + let percentageOfStudents = groupPercentage(numberOfStudents, numberOfMentors); + let percentageOfMentors = groupPercentage (numberOfMentors, numberOfStudents); + return displayPercentage = `Percentage students: ${percentageOfStudents}%\nPercentage students: ${percentageOfMentors}%`; +} + let percentage = message(15, 8); + console.log(percentage); + + +// Exercise 2 + var mentor1 = "Daniel"; var mentor2 = "Irina"; var mentor3 = "Mimi"; var mentor4 = "Rob"; var mentor5 = "Yohannes"; + +function shoutyGreeting(mentor){ + let blockNames = mentor.toUpperCase(); + return greeting = `HELLO ${blockNames}`; + +} + +var firstGreeting = shoutyGreeting(mentor1); +var seccondGreeting = shoutyGreeting(mentor2); +var thirdGreeting = shoutyGreeting(mentor3); +var fourthGreeting = shoutyGreeting(mentor4); +var fifthGreeting = shoutyGreeting(mentor5); + +console.log(firstGreeting); +console.log(seccondGreeting); +console.log(thirdGreeting); +console.log(fourthGreeting); +console.log(fifthGreeting); \ No newline at end of file From 763309a09777af6a3d5b3a68af3eb7e01db15579 Mon Sep 17 00:00:00 2001 From: Wahab Rehman Date: Thu, 7 Jan 2021 20:10:42 +0000 Subject: [PATCH 6/6] small changes --- exercises/C-variables/exercise.js | 2 +- exercises/E-strings-concatenation/exercise.js | 8 +++++--- exercises/F-strings-methods/exercise.js | 6 +++++- exercises/I-floats/exercise.js | 14 +++++++------- exercises/J-functions/exercise.js | 6 +++--- exercises/J-functions/exercise2.js | 2 +- exercises/K-functions-parameters/exercise.js | 2 +- exercises/K-functions-parameters/exercise2.js | 2 +- exercises/K-functions-parameters/exercise3.js | 2 +- 9 files changed, 25 insertions(+), 19 deletions(-) diff --git a/exercises/C-variables/exercise.js b/exercises/C-variables/exercise.js index 03719cf97..b0ef1742c 100644 --- a/exercises/C-variables/exercise.js +++ b/exercises/C-variables/exercise.js @@ -1,5 +1,5 @@ // Start by creating a variable `greeting` -var greeting = "hello world" +let greeting = "hello world" console.log(greeting); console.log(greeting); console.log(greeting); \ No newline at end of file diff --git a/exercises/E-strings-concatenation/exercise.js b/exercises/E-strings-concatenation/exercise.js index b8ba4daaa..b065c892d 100644 --- a/exercises/E-strings-concatenation/exercise.js +++ b/exercises/E-strings-concatenation/exercise.js @@ -1,7 +1,9 @@ // Start by creating a variable `message` -var greet = "Hello, my name is "; -var name = "Monique"; +let greet = "Hello, my name is "; +let name = "Monique"; -var greeting = greet + name; +let greeting = greet + name; console.log(greeting); + +//Try to use let instead of var. Its best practice to use let :) diff --git a/exercises/F-strings-methods/exercise.js b/exercises/F-strings-methods/exercise.js index 767f8dfc0..c49cf82d1 100644 --- a/exercises/F-strings-methods/exercise.js +++ b/exercises/F-strings-methods/exercise.js @@ -1,6 +1,10 @@ // Start by creating a variable `message` -let name = "Monique"; +let name = "Monique"; let nameLength = name.length; +//Yours console.log(`My name is ${name} and my name is ${name.length} characters long`); +//This is fine but remember you already made a varible for nameLength, so try to use as well ;) +console.log(`My name is ${name} and my name is ${nameLength} characters long`); + diff --git a/exercises/I-floats/exercise.js b/exercises/I-floats/exercise.js index df8b3ec43..699f55567 100644 --- a/exercises/I-floats/exercise.js +++ b/exercises/I-floats/exercise.js @@ -1,12 +1,12 @@ -var numberOfStudents = 15; -var numberOfMentors = 8; +let numberOfStudents = 15; +let numberOfMentors = 8; -var total = numberOfStudents + numberOfMentors; +let total = numberOfStudents + numberOfMentors; -var convertStudents = numberOfStudents / total * 100; -var convertMentors = numberOfMentors / total * 100; -var percentageOfStudents = Math.round(convertStudents); -var percentageOfMentors = Math.round(convertMentors); +let convertStudents = numberOfStudents / total * 100; +let convertMentors = numberOfMentors / total * 100; +let percentageOfStudents = Math.round(convertStudents); +let percentageOfMentors = Math.round(convertMentors); console.log(`Percentage students: ${percentageOfStudents}%`); console.log(`Percentage students: ${percentageOfMentors}%`); \ No newline at end of file diff --git a/exercises/J-functions/exercise.js b/exercises/J-functions/exercise.js index 5cf5635d5..443708e22 100644 --- a/exercises/J-functions/exercise.js +++ b/exercises/J-functions/exercise.js @@ -2,9 +2,9 @@ function halve(number) { return number / 2;// complete the function here } -var result = halve(12); -var result1 = halve(10); -var result2 = halve(9); +let result = halve(12); +let result1 = halve(10); +let result2 = halve(9); console.log(result); console.log(result1); diff --git a/exercises/J-functions/exercise2.js b/exercises/J-functions/exercise2.js index 946e2ba3a..791b6b0c2 100644 --- a/exercises/J-functions/exercise2.js +++ b/exercises/J-functions/exercise2.js @@ -3,6 +3,6 @@ function triple(number) { return number * 3// complete function here } -var result = triple(12); +let result = triple(12); console.log(result); \ No newline at end of file diff --git a/exercises/K-functions-parameters/exercise.js b/exercises/K-functions-parameters/exercise.js index 92cdc648d..86fbf17f8 100644 --- a/exercises/K-functions-parameters/exercise.js +++ b/exercises/K-functions-parameters/exercise.js @@ -4,6 +4,6 @@ function multiply(num1, num2) { } // Assign the result of calling the function the variable `result` -var result = multiply(3, 4); +let result = multiply(3, 4); console.log(result); \ No newline at end of file diff --git a/exercises/K-functions-parameters/exercise2.js b/exercises/K-functions-parameters/exercise2.js index 5b917e0b9..0f6520721 100644 --- a/exercises/K-functions-parameters/exercise2.js +++ b/exercises/K-functions-parameters/exercise2.js @@ -3,6 +3,6 @@ function divide (num1, num2) { return num1 / num2; } // Declare your function first -var result = divide(3, 4); +let result = divide(3, 4); console.log(result); \ No newline at end of file diff --git a/exercises/K-functions-parameters/exercise3.js b/exercises/K-functions-parameters/exercise3.js index e0463d216..abef98e9c 100644 --- a/exercises/K-functions-parameters/exercise3.js +++ b/exercises/K-functions-parameters/exercise3.js @@ -2,6 +2,6 @@ function createGreeting (name) { return `Hello, my name is ${name}`; } -var greeting = createGreeting("Daniel"); +let greeting = createGreeting("Daniel"); console.log(greeting); \ No newline at end of file