From 19457ec62b85c728269fc2d1e91073b75a225f36 Mon Sep 17 00:00:00 2001 From: Kos0606 <65927936+Kos0606@users.noreply.github.com> Date: Mon, 7 Dec 2020 20:59:12 +0000 Subject: [PATCH 1/6] cd B-hello-world --- exercises/B-hello-world/exercise.js | 1 + 1 file changed, 1 insertion(+) diff --git a/exercises/B-hello-world/exercise.js b/exercises/B-hello-world/exercise.js index b179ee953..b354a3eaf 100644 --- a/exercises/B-hello-world/exercise.js +++ b/exercises/B-hello-world/exercise.js @@ -1 +1,2 @@ console.log("Hello world"); +console.log("Hello World. I just started learning JavaScript!".); From 7a8cc27ce040c0fd9ee17275967716f6643ffbd0 Mon Sep 17 00:00:00 2001 From: Kos0606 <65927936+Kos0606@users.noreply.github.com> Date: Mon, 7 Dec 2020 21:25:24 +0000 Subject: [PATCH 2/6] cd B-hello-world --- exercises/B-hello-world/exercise.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/exercises/B-hello-world/exercise.js b/exercises/B-hello-world/exercise.js index b354a3eaf..18266df81 100644 --- a/exercises/B-hello-world/exercise.js +++ b/exercises/B-hello-world/exercise.js @@ -1,2 +1,3 @@ console.log("Hello world"); -console.log("Hello World. I just started learning JavaScript!".); +console.log('Hello World. I just started learning JavaScript!.'); + From cd989ec65c3cc511d57e1a2d7461ec80742593aa Mon Sep 17 00:00:00 2001 From: Kos0606 <65927936+Kos0606@users.noreply.github.com> Date: Mon, 7 Dec 2020 23:18:59 +0000 Subject: [PATCH 3/6] C-Variable --- exercises/B-hello-world/README.md | 2 +- exercises/B-hello-world/exercise.js | 4 ++-- exercises/C-variables/exercise.js | 4 +++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/exercises/B-hello-world/README.md b/exercises/B-hello-world/README.md index a7b891d56..eb6b838dd 100644 --- a/exercises/B-hello-world/README.md +++ b/exercises/B-hello-world/README.md @@ -4,7 +4,7 @@ We'll do this in JavaScript, using something called `console.log()`. Inside of `exercise.js` there's a line of code that will print "Hello world!". -### 1. Run the program +### 1. Run the programcd * Open a terminal window * Change directory to this folder (`cd B-hello-world`) diff --git a/exercises/B-hello-world/exercise.js b/exercises/B-hello-world/exercise.js index 18266df81..0e81066c2 100644 --- a/exercises/B-hello-world/exercise.js +++ b/exercises/B-hello-world/exercise.js @@ -1,3 +1,3 @@ -console.log("Hello world"); -console.log('Hello World. I just started learning JavaScript!.'); +console.log('Hello World. I just started learning JavaScript!. I love it.'); +console.log(5); diff --git a/exercises/C-variables/exercise.js b/exercises/C-variables/exercise.js index a6bbb9786..4a9303f11 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 From 457e31787cf7fa6fd21a12d72d485526dd287be5 Mon Sep 17 00:00:00 2001 From: Kos0606 <65927936+Kos0606@users.noreply.github.com> Date: Tue, 8 Dec 2020 22:16:46 +0000 Subject: [PATCH 4/6] Javascript-core-1 --- exercises/D-strings/README.md | 2 +- exercises/D-strings/exercise.js | 4 +++- exercises/E-strings-concatenation/exercise.js | 3 +++ exercises/F-strings-methods/exercise.js | 5 +++-- exercises/F-strings-methods/exercise2.js | 2 +- exercises/G-numbers/exercise.js | 4 ++++ exercises/I-floats/exercise.js | 4 ++++ exercises/J-functions/exercise.js | 10 ++++++++-- exercises/J-functions/exercise2.js | 9 +++++++-- exercises/K-functions-parameters/README.md | 12 ++++++------ exercises/K-functions-parameters/exercise.js | 3 ++- exercises/K-functions-parameters/exercise2.js | 6 ++++-- exercises/K-functions-parameters/exercise3.js | 3 +++ exercises/K-functions-parameters/exercise4.js | 4 ++++ exercises/K-functions-parameters/exercise5.js | 3 +++ exercises/L-functions-nested/exercicise1.js | 8 ++++++++ 16 files changed, 64 insertions(+), 18 deletions(-) create mode 100644 exercises/L-functions-nested/exercicise1.js diff --git a/exercises/D-strings/README.md b/exercises/D-strings/README.md index 1516f536e..fd0a664ae 100644 --- a/exercises/D-strings/README.md +++ b/exercises/D-strings/README.md @@ -19,7 +19,7 @@ console.log(messageType); // logs 'string' ## Exercise -* Write a program that logs a message and its type +- Write a program that logs a message and its type ## Expected result diff --git a/exercises/D-strings/exercise.js b/exercises/D-strings/exercise.js index 2cffa6a81..746513ef2 100644 --- a/exercises/D-strings/exercise.js +++ b/exercises/D-strings/exercise.js @@ -1,3 +1,5 @@ // Start by creating a variable `message` - +var message = "I love Code Your Future"; 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..0cee7b761 100644 --- a/exercises/E-strings-concatenation/exercise.js +++ b/exercises/E-strings-concatenation/exercise.js @@ -1,3 +1,6 @@ // Start by creating a variable `message` +var greetingStart ="Hello, my name is"; +var firstName = "Kos"; +var message = greetingStart + " " + firstName; console.log(message); diff --git a/exercises/F-strings-methods/exercise.js b/exercises/F-strings-methods/exercise.js index 2cffa6a81..aa37d3c51 100644 --- a/exercises/F-strings-methods/exercise.js +++ b/exercises/F-strings-methods/exercise.js @@ -1,3 +1,4 @@ // Start by creating a variable `message` - -console.log(message); +var name ="Kos"; +var message = name.length; +console.log("My name is Kos and my name is" + " " + message + " " + "characters long"); diff --git a/exercises/F-strings-methods/exercise2.js b/exercises/F-strings-methods/exercise2.js index b4b46943d..c50400331 100644 --- a/exercises/F-strings-methods/exercise2.js +++ b/exercises/F-strings-methods/exercise2.js @@ -1,3 +1,3 @@ const name = " Daniel "; - +var message = name.trim(); console.log(message); diff --git a/exercises/G-numbers/exercise.js b/exercises/G-numbers/exercise.js index 49e7bc00b..9b278fa24 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 = numberOfStudents + numberOfMentors; +console.log("Total number of students and mentors is:" + " " + total); \ No newline at end of file diff --git a/exercises/I-floats/exercise.js b/exercises/I-floats/exercise.js index a5bbcd852..6dce84001 100644 --- a/exercises/I-floats/exercise.js +++ b/exercises/I-floats/exercise.js @@ -1,2 +1,6 @@ var numberOfStudents = 15; var numberOfMentors = 8; +var percentage_1 = numberOfStudents / (numberOfStudents + numberOfMentors)*100; +var percentage_2 = numberOfMentors / (numberOfStudents + numberOfMentors)*100; +console.log("Percentage students:" + " " + Math.round(percentage_1) + "%"); +console.log("Percentage mentors:" + " " + Math.round(percentage_2) + "%"); diff --git a/exercises/J-functions/exercise.js b/exercises/J-functions/exercise.js index 0ae5850e5..a7b49ced4 100644 --- a/exercises/J-functions/exercise.js +++ b/exercises/J-functions/exercise.js @@ -1,7 +1,13 @@ function halve(number) { // complete the function here + return number / 2; } -var result = halve(12); +var result_1 = halve(12); +var result_2 = halve(24); +var result_3 = halve(15); + +console.log(result_1); +console.log(result_2); +console.log(result_3); -console.log(result); diff --git a/exercises/J-functions/exercise2.js b/exercises/J-functions/exercise2.js index 82ef5e780..702e5ab17 100644 --- a/exercises/J-functions/exercise2.js +++ b/exercises/J-functions/exercise2.js @@ -1,7 +1,12 @@ function triple(number) { // complete function here + return number*3; } -var result = triple(12); +var result_1 = triple(12); +var result_2 = triple(50); +var result_3 = triple(120); -console.log(result); +console.log(result_1); +console.log(result_2); +console.log(result_3); diff --git a/exercises/K-functions-parameters/README.md b/exercises/K-functions-parameters/README.md index 02ab2a844..1614e221b 100644 --- a/exercises/K-functions-parameters/README.md +++ b/exercises/K-functions-parameters/README.md @@ -20,7 +20,7 @@ function add(num1, num2) { ## Exercise -* Write a function that multiplies two numbers together +- Write a function that multiplies two numbers together ## Expected result @@ -30,7 +30,7 @@ function add(num1, num2) { ## Exercise 2 -* From scratch, write a function that divides two numbers +- From scratch, write a function that divides two numbers ## Expected result @@ -40,7 +40,7 @@ function add(num1, num2) { ## Exercise 3 -* Write a function that takes a name (a string) and returns a greeting +- Write a function that takes a name (a string) and returns a greeting ## Expected result @@ -50,8 +50,8 @@ Hello, my name is Daniel ## Exercise 4 -* Write a function that adds two numbers together -* Call the function, passing `13` and `124` as parameters, and assigning the returned value to a variable `sum` +- Write a function that adds two numbers together +- Call the function, passing `13` and `124` as parameters, and assigning the returned value to a variable `sum` ## Expected result @@ -61,7 +61,7 @@ Hello, my name is Daniel ## Exercise 5 -* Write a function that takes a name (a string) and an age (a number) and returns a greeting (a string) +- Write a function that takes a name (a string) and an age (a number) and returns a greeting (a string) ## Expected result diff --git a/exercises/K-functions-parameters/exercise.js b/exercises/K-functions-parameters/exercise.js index 8d5db5e69..46e0bb26a 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..831dff9f4 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); +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..0a2f95b08 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..ba078c111 100644 --- a/exercises/K-functions-parameters/exercise4.js +++ b/exercises/K-functions-parameters/exercise4.js @@ -1,5 +1,9 @@ // Declare your function first +function Add(x, y) { + return x + y; +} // Call the function and assign to a variable `sum` +var 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..0b3244010 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/exercicise1.js b/exercises/L-functions-nested/exercicise1.js new file mode 100644 index 000000000..727cd5ed2 --- /dev/null +++ b/exercises/L-functions-nested/exercicise1.js @@ -0,0 +1,8 @@ +function participant(students, mentors) { + var percentStudents = students / (students + mentors)*100; + var percentMentors = mentors / (students + mentors)*100; + return "Percentage students:" + Math.round(percentStudents) + "%" + " " + " " + " " + "Percentage mentors:" + Math.round(percentMentors) + "%"; + +} +var result = participant(15, 8); +console.log(result); From 1d433a7d8df9e30f133e428d8146bd0e5b13dfea Mon Sep 17 00:00:00 2001 From: Kos0606 <65927936+Kos0606@users.noreply.github.com> Date: Wed, 9 Dec 2020 23:10:46 +0000 Subject: [PATCH 5/6] JavaScrip-Core-1 --- exercises/L-functions-nested/exercise.js | 63 ++++++++++++++++++++++++ extra/1-currency-conversion.js | 11 ++++- extra/2-piping.js | 21 ++++++-- mandatory/1-syntax-errors.js | 14 +++--- mandatory/2-logic-error.js | 19 ++++--- 5 files changed, 107 insertions(+), 21 deletions(-) diff --git a/exercises/L-functions-nested/exercise.js b/exercises/L-functions-nested/exercise.js index a5d377442..9c937fea0 100644 --- a/exercises/L-functions-nested/exercise.js +++ b/exercises/L-functions-nested/exercise.js @@ -3,3 +3,66 @@ var mentor2 = "Irina"; var mentor3 = "Mimi"; var mentor4 = "Rob"; var mentor5 = "Yohannes"; + +function nameToUppercase_1(mentor1) { + return mentor1.toUpperCase(); +} +var writtenInUpperCase_1 = nameToUppercase_1("Daniel"); +console.log(writtenInUpperCase_1); + +function nameToUppercase_2(mentor2) { + return mentor2.toUpperCase(); +} +var writtenInUpperCase_2 = nameToUppercase_2("Irina"); +console.log(writtenInUpperCase_2); + +function nameToUppercase_3(mentor3) { + return mentor3.toUpperCase(); +} +var writtenInUpperCase_3 = nameToUppercase_3("Mimi"); +console.log(writtenInUpperCase_3); + +function nameToUppercase_4(mentor4) { + return mentor4.toUpperCase(); +} +var writtenInUpperCase_4 = nameToUppercase_4("Rob"); +console.log(writtenInUpperCase_4); + +function nameToUppercase_5(mentor5) { + return mentor5.toUpperCase(); +} +var writtenInUpperCase_5 = nameToUppercase_5("Yohannes"); +console.log(writtenInUpperCase_5); + + +function createGreeting1(mentor1) { + return mentor1.toUpperCase(); +} +var message1 ="HELLO" + " " + mentor1.toUpperCase(); +console.log(message1); + + +function createGreeting2(mentor2) { + return mentor1.toUpperCase(); +} +var message2 ="HELLO" + " " + mentor2.toUpperCase(); +console.log(message2); + +function createGreeting3(mentor3) { + return mentor3.toUpperCase(); +} +var message3 ="HELLO" + " " + mentor3.toUpperCase(); +console.log(message3); + +function createGreeting4(mentor4) { + return mentor4.toUpperCase(); +} +var message4 ="HELLO" + " " + mentor1.toUpperCase(); +console.log(message4); + + +function createGreeting5(mentor5) { + return mentor5.toUpperCase(); +} +var message5 ="HELLO" + " " + mentor1.toUpperCase(); +console.log(message5); \ No newline at end of file diff --git a/extra/1-currency-conversion.js b/extra/1-currency-conversion.js index 70a2fe863..b18c6e400 100644 --- a/extra/1-currency-conversion.js +++ b/extra/1-currency-conversion.js @@ -5,7 +5,11 @@ Write a function that converts a price to USD (exchange rate is 1.4 $ to £) */ -function convertToUSD() {} +function convertToUSD(price1) { + return price1 * 1.4; + +} +convertToUSD(3.15); /* CURRENCY FORMATTING @@ -15,7 +19,10 @@ function convertToUSD() {} They have also decided that they should add a 1% fee to all foreign transactions, which means you only convert 99% of the £ to BRL. */ -function convertToBRL() {} +function convertToBRL(price2) { + return price2 * 5.7 * 99/100; +} + convertToBRL(30); /* ======= TESTS - DO NOT MODIFY ===== There are some Tests in this file that will help you work out if your code is working. diff --git a/extra/2-piping.js b/extra/2-piping.js index 067dd0f5b..595862f28 100644 --- a/extra/2-piping.js +++ b/extra/2-piping.js @@ -16,26 +16,37 @@ the final result to the variable goodCode */ -function add() { +function add(a, b) { + return a + b; } +add(1, 3); -function multiply() { +function multiply(x, y) { + return x * y; } +multiply(2, 3); -function format() { +function format(number) { + return "£" + number; } +format(16); const startingValue = 2 // Why can this code be seen as bad practice? Comment your answer. -let badCode = +let badCode = "£" + (startingValue + 10) * 2; + +// This is bad practice because all written in one line and difficult to understand and possibly debugging. /* BETTER PRACTICE */ -let goodCode = +let adding = 10 + startingValue; +let timing = adding * 2; +let goodCode = "£" + timing; + /* ======= TESTS - DO NOT MODIFY ===== There are some Tests in this file that will help you work out if your code is working. diff --git a/mandatory/1-syntax-errors.js b/mandatory/1-syntax-errors.js index 0a21afd1b..dd58c9cf6 100644 --- a/mandatory/1-syntax-errors.js +++ b/mandatory/1-syntax-errors.js @@ -1,18 +1,20 @@ // 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" + " " + (a + b); - return "The total is total" + } - +getTotal(23,5); + /* =================================================== ======= TESTS - DO NOT MODIFY BELOW THIS LINE ===== diff --git a/mandatory/2-logic-error.js b/mandatory/2-logic-error.js index 3c578ad87..0823960a6 100644 --- a/mandatory/2-logic-error.js +++ b/mandatory/2-logic-error.js @@ -1,17 +1,20 @@ // The syntax for this function is valid but it has an error, find it and fix it. -function trimWord(word) { - return wordtrim(); -} +var trimWord = " CodeYourFuture "; + trimWord.trim(); + + +var getWordLength = "A wild sentence appeared!"; + getWordLength.length; + + -function getWordLength(word) { - return "word".length(); -} function multiply(a, b, c) { - a * b * c; - return; + + return a * b * c; } +multiply(2, 3, 6); /* =================================================== From 760edc3557452125d0fa3b570a59bd272bcf101b Mon Sep 17 00:00:00 2001 From: Kos0606 <65927936+Kos0606@users.noreply.github.com> Date: Thu, 10 Dec 2020 22:09:24 +0000 Subject: [PATCH 6/6] JavaScript-Core-1 --- mandatory/2-logic-error.js | 12 ++++++++---- mandatory/3-function-output.js | 10 +++++++++- mandatory/4-tax.js | 14 ++++++++++++-- 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/mandatory/2-logic-error.js b/mandatory/2-logic-error.js index 0823960a6..5a0db5855 100644 --- a/mandatory/2-logic-error.js +++ b/mandatory/2-logic-error.js @@ -1,11 +1,15 @@ // The syntax for this function is valid but it has an error, find it and fix it. -var trimWord = " CodeYourFuture "; - trimWord.trim(); +function trimWord(word) { + return word.trim(); +} +trimWord(" CodeYourFuture "); -var getWordLength = "A wild sentence appeared!"; - getWordLength.length; +function getWordLength(word) { +return word.length; +} + getWordLength("A wild sentence appeared!"); diff --git a/mandatory/3-function-output.js b/mandatory/3-function-output.js index c9221a200..8328ae072 100644 --- a/mandatory/3-function-output.js +++ b/mandatory/3-function-output.js @@ -1,18 +1,26 @@ // Add comments to explain what this function does. You're meant to use Google! +/* The Math.random() function returns a floating-point. Numbers are selected between 0 inclusive and 1 exclusive. +However, Math.random()*10 select random floating point number between 0 and 10 */ + function getNumber() { return Math.random() * 10; } // Add comments to explain what this function does. You're meant to use Google! + +// This function takes the value of w1 and add the value of w2 function s(w1, w2) { return w1.concat(w2); } + 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(" ").concat(secondWord).concat(" ").concat(thirdWord); } - +concatenate("code", "your", "future"); /* =================================================== ======= TESTS - DO NOT MODIFY BELOW THIS LINE ===== diff --git a/mandatory/4-tax.js b/mandatory/4-tax.js index c9e41c691..711c28119 100644 --- a/mandatory/4-tax.js +++ b/mandatory/4-tax.js @@ -5,7 +5,12 @@ Sales tax is 20% of the price of the product */ -function calculateSalesTax() {} +function calculateSalesTax(price) { + var salesTax = price + price * 20/100; + return salesTax; + +} +calculateSalesTax(15); /* CURRENCY FORMATTING @@ -17,7 +22,12 @@ function calculateSalesTax() {} Remember that the prices must include the sales tax (hint: you already wrote a function for this!) */ -function addTaxAndFormatCurrency() {} +function addTaxAndFormatCurrency(price) { + var sellingPrice = price + price * 20/100; + return "£" + sellingPrice.toFixed(2); + +} +addTaxAndFormatCurrency(17.5); /* ===================================================