From 92531338e3bf358e22338e9f038699328c9cb07b Mon Sep 17 00:00:00 2001 From: aalassv Date: Sat, 3 Jul 2021 09:53:34 +0100 Subject: [PATCH 1/3] All required exercise done, extra not yet --- exercises/B-hello-world/exercise.js | 48 +++++++++++++++++++ exercises/C-variables/exercise.js | 5 +- exercises/D-strings/exercise.js | 15 ++++++ exercises/E-strings-concatenation/exercise.js | 6 ++- exercises/F-strings-methods/exercise.js | 25 +++++++++- exercises/F-strings-methods/exercise2.js | 5 +- exercises/G-numbers/exercise.js | 17 +++++++ exercises/I-floats/exercise.js | 24 +++++++++- exercises/J-functions/exercise.js | 12 ++++- exercises/J-functions/exercise2.js | 4 +- exercises/K-functions-parameters/exercise.js | 6 +-- exercises/K-functions-parameters/exercise2.js | 6 ++- exercises/K-functions-parameters/exercise3.js | 6 ++- exercises/K-functions-parameters/exercise4.js | 6 ++- exercises/K-functions-parameters/exercise5.js | 4 +- exercises/L-functions-nested/exercise.js | 23 +++++++-- extra/1-currency-conversion.js | 18 +++++-- 17 files changed, 201 insertions(+), 29 deletions(-) diff --git a/exercises/B-hello-world/exercise.js b/exercises/B-hello-world/exercise.js index b179ee953..f817f2e74 100644 --- a/exercises/B-hello-world/exercise.js +++ b/exercises/B-hello-world/exercise.js @@ -1 +1,49 @@ console.log("Hello world"); +console.log("Testing console.log"); +console.log("Show a lot to do."); +console.log("Amazing console that LOG"); + +let person1 = " Israel "; +let activity = " Skateboarding "; +let goOut = " To the park "; +let likes = "It is a person who likes"; +let noLikes = "It is a person who do not likes"; +let numberBig = 1324123451235; +let isTrueOr = true; +let isFalseOr = false; +let story = + isFalseOr + + isTrueOr + + person1 + + numberBig + + noLikes + + " play baseball" + + " his " + + activity + + " is better than anything"; + +console.log("begin of the story"); +console.log(story); + +function myFunctionName() { + console.log(goOut); + console.log(likes); + console.log(story); +} + +console.log("the function results"); +myFunctionName(); + +function someTest(num1, num2, num3, num4) { + return "The numbers you gave us SUM: " + num1 + num2 + num3 + num4; +} +console.log("sum"); +someTest(700, 44, 600, 100); + +//Experiment +console.log("This is the test with out quotes"); +console.log( + "If you do not use quotes an error message will appear to you saying: SyntaxError: missing ) after argument list" +); +console.log(100); +console.log("Console.log works with numbers too, with out quotes"); diff --git a/exercises/C-variables/exercise.js b/exercises/C-variables/exercise.js index a6bbb9786..19b5b7e53 100644 --- a/exercises/C-variables/exercise.js +++ b/exercises/C-variables/exercise.js @@ -1,3 +1,6 @@ // 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..3d83ac165 100644 --- a/exercises/D-strings/exercise.js +++ b/exercises/D-strings/exercise.js @@ -1,3 +1,18 @@ // Start by creating a variable `message` +let message = "This is a string" +//log console.log(message); + + +let messageType = typeof message; +console.log(messageType); +//log +console.log(typeof(message)); + + +let myMessage = "Using typeof command to know what data type is and this is: " +let myMsmDataType = typeof myMessage; +//log +console.log(myMessage,myMsmDataType); + diff --git a/exercises/E-strings-concatenation/exercise.js b/exercises/E-strings-concatenation/exercise.js index 2cffa6a81..2153e678f 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 message = "Hello, my name is "; +let myName = "Israel"; +let greeting = message + myName; +//log +console.log(greeting); -console.log(message); diff --git a/exercises/F-strings-methods/exercise.js b/exercises/F-strings-methods/exercise.js index 2cffa6a81..fd55c5ae8 100644 --- a/exercises/F-strings-methods/exercise.js +++ b/exercises/F-strings-methods/exercise.js @@ -1,3 +1,26 @@ // Start by creating a variable `message` -console.log(message); +let myName = "Israel"; +let nameLength = myName.length; +//log +console.log(nameLength); + +//Using string methods +let myNameInLowerCase = myName.toLowerCase(); +//log +console.log(myNameInLowerCase); + +let exerciseOne = + "My name is " + myName + " and my name is " + nameLength + " characters long"; +//log +console.log(exerciseOne); + +const name = " Daniel "; + +//log +let exerciseTwo = "My name is " + name + " and my name is " + nameLength + " characters long"; +console.log(exerciseTwo); +//With trim +exerciseTwo = "My name is " + name.trim() + " and my name is " + nameLength + " characters long"; +console.log(exerciseTwo); + diff --git a/exercises/F-strings-methods/exercise2.js b/exercises/F-strings-methods/exercise2.js index b4b46943d..9c15fc978 100644 --- a/exercises/F-strings-methods/exercise2.js +++ b/exercises/F-strings-methods/exercise2.js @@ -1,3 +1,6 @@ const name = " Daniel "; -console.log(message); +let exerciseOne = + "My name is " + name+ " and my name is " + nameLength + " characters long"; +//log +console.log(exerciseOne); diff --git a/exercises/G-numbers/exercise.js b/exercises/G-numbers/exercise.js index 49e7bc00b..6876451bc 100644 --- a/exercises/G-numbers/exercise.js +++ b/exercises/G-numbers/exercise.js @@ -1 +1,18 @@ // Start by creating a variables `numberOfStudents` and `numberOfMentors` +let age = 37; +let sum = 10 + 234; +let product = 245 * 23; +let quotient = 10 / 2; +let difference = 10 - 4; + +//Exercises + +let numberOfStudents = 100; +let numberOfMentors = 25; + +console.log( + "Total number of student: " + + numberOfStudents + + " and mentors: " + + numberOfMentors +); diff --git a/exercises/I-floats/exercise.js b/exercises/I-floats/exercise.js index a5bbcd852..780e047e0 100644 --- a/exercises/I-floats/exercise.js +++ b/exercises/I-floats/exercise.js @@ -1,2 +1,22 @@ -var numberOfStudents = 15; -var numberOfMentors = 8; + +let numberOfStudents = 15; +let numberOfMentors = 8; + +//Some test +let preciseAge = 30.612437; +//get that number rounded using Math.round +let roughAge = Math.round(preciseAge); +//log +//console.log(roughAge); //31 + +//lets sum both values Student and Mentors +let totalAmount = numberOfMentors+numberOfStudents; +//Divide - multiply and round +let percentageValue = Math.round((numberOfStudents/totalAmount)*100); +//log for students +console.log("Percentage students "+percentageValue+"%"); + +//Divide - multiply and round +percentageValue = Math.round((numberOfMentors/totalAmount)*100); +//log for metors +console.log("Percentage mentors "+percentageValue+"%"); \ No newline at end of file diff --git a/exercises/J-functions/exercise.js b/exercises/J-functions/exercise.js index 0ae5850e5..9da6da27f 100644 --- a/exercises/J-functions/exercise.js +++ b/exercises/J-functions/exercise.js @@ -1,7 +1,15 @@ function halve(number) { - // complete the function here + return number / 2; } var result = halve(12); - +//log +console.log(result); +//log-1 +result = halve(245); +//log console.log(result); +//log-2 +result = halve(59934); +//log +console.log(result); \ No newline at end of file diff --git a/exercises/J-functions/exercise2.js b/exercises/J-functions/exercise2.js index 82ef5e780..0df95e216 100644 --- a/exercises/J-functions/exercise2.js +++ b/exercises/J-functions/exercise2.js @@ -1,7 +1,7 @@ function triple(number) { - // complete function here + return number * 3; } -var result = triple(12); +let result = triple(12); console.log(result); diff --git a/exercises/K-functions-parameters/exercise.js b/exercises/K-functions-parameters/exercise.js index 8d5db5e69..e17a7f893 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(num01, num02) { + return num01 * num02; } // Assign the result of calling the function the variable `result` -var result = multiply(3, 4); +let result = multiply(3, 4); console.log(result); diff --git a/exercises/K-functions-parameters/exercise2.js b/exercises/K-functions-parameters/exercise2.js index db7a8904b..f4db3227a 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); +let 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..f71c62566 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 (str){ + return "Hello, my name is " + str; +} -var greeting = createGreeting("Daniel"); +let greeting = createGreeting("Daniel"); console.log(greeting); diff --git a/exercises/K-functions-parameters/exercise4.js b/exercises/K-functions-parameters/exercise4.js index 7ab44589e..0b416bac1 100644 --- a/exercises/K-functions-parameters/exercise4.js +++ b/exercises/K-functions-parameters/exercise4.js @@ -1,5 +1,7 @@ -// Declare your function first +function addition (num1, num2){ + return num1 + num2; +} -// Call the function and assign to a variable `sum` +let sum = addition(13,124); console.log(sum); diff --git a/exercises/K-functions-parameters/exercise5.js b/exercises/K-functions-parameters/exercise5.js index 7c5bcd605..eb76e979c 100644 --- a/exercises/K-functions-parameters/exercise5.js +++ b/exercises/K-functions-parameters/exercise5.js @@ -1,4 +1,6 @@ -// Declare your function here +function createLongGreeting(str, ages) { + return "Hello, my names is " + str + " and I'm " + ages + " 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..fdc765c1b 100644 --- a/exercises/L-functions-nested/exercise.js +++ b/exercises/L-functions-nested/exercise.js @@ -1,5 +1,18 @@ -var mentor1 = "Daniel"; -var mentor2 = "Irina"; -var mentor3 = "Mimi"; -var mentor4 = "Rob"; -var mentor5 = "Yohannes"; +let mentor1 = "Daniel"; +let mentor2 = "Irina"; +let mentor3 = "Mimi"; +let mentor4 = "Rob"; +let mentor5 = "Yohannes"; + +function uppercaseNames (str){ + return nameUppercased = str.toUpperCase(); +} + +function shoutyGreet (name){ + return "HELLO "+uppercaseNames(name); +} +console.log(shoutyGreet(mentor1)); +console.log(shoutyGreet(mentor2)); +console.log(shoutyGreet(mentor3)); +console.log(shoutyGreet(mentor4)); +console.log(shoutyGreet(mentor5)); diff --git a/extra/1-currency-conversion.js b/extra/1-currency-conversion.js index d82e59480..c1a035c19 100644 --- a/extra/1-currency-conversion.js +++ b/extra/1-currency-conversion.js @@ -5,17 +5,26 @@ Write a function that converts a price to USD (exchange rate is 1.4 $ to £) */ -function convertToUSD() {} +//function convertToUSD(price) { + // return price * 1.4; +//} +//console.log(convertToUSD(100)); /* CURRENCY CONVERSION =================== The business is now breaking into the Brazilian market Write a new function for converting to the Brazilian real (exchange rate is 5.7 BRL to £) - 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. + 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(priceB) { + substPercent = (priceB / 99) * 99 ; +return substPercent * 5.7; +} + +console.log(convertToBRL(100.00)); /* ======= TESTS - DO NOT MODIFY ===== There are some Tests in this file that will help you work out if your code is working. @@ -23,7 +32,7 @@ There are some Tests in this file that will help you work out if your code is wo To run these tests type `npm run extraTo run the tests for just this one file, type `npm run extra-tests -- --testPathPattern 1-syntax-errors` into your terminal (Reminder: You must have run `npm install` one time before this will work!) */ - +/* test("convertToUSD function works for £32", () => { expect(convertToUSD(32)).toEqual(44.8); }); @@ -39,3 +48,4 @@ test("convertToBRL function works for £30", () => { test("convertToBRL function works for £1.50", () => { expect(convertToBRL(1.5)).toEqual(8.46); }); +*/ \ No newline at end of file From de6764fecc9c2b6f8c20db84f52bdafde9c0ff6d Mon Sep 17 00:00:00 2001 From: aalassv Date: Thu, 8 Jul 2021 01:32:12 +0100 Subject: [PATCH 2/3] Al exercises done Sorry but the Magic ball maybe need more time to sorted out. --- extra/1-currency-conversion.js | 17 +++++++-------- extra/2-piping.js | 38 +++++++++++++++++++++++++--------- extra/3-magic-8-ball.js | 30 ++++++++++++++++----------- mandatory/1-syntax-errors.js | 6 +++--- mandatory/2-logic-error.js | 7 +++---- mandatory/3-function-output.js | 6 +++--- mandatory/4-tax.js | 16 ++++++++++---- 7 files changed, 75 insertions(+), 45 deletions(-) diff --git a/extra/1-currency-conversion.js b/extra/1-currency-conversion.js index c1a035c19..8ebc7887c 100644 --- a/extra/1-currency-conversion.js +++ b/extra/1-currency-conversion.js @@ -5,10 +5,10 @@ Write a function that converts a price to USD (exchange rate is 1.4 $ to £) */ -//function convertToUSD(price) { - // return price * 1.4; -//} -//console.log(convertToUSD(100)); +function convertToUSD(price) { +return price * 1.4; +} +console.log(convertToUSD(32)); /* CURRENCY CONVERSION @@ -16,15 +16,15 @@ The business is now breaking into the Brazilian market Write a new function for converting to the Brazilian real (exchange rate is 5.7 BRL to £) 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. + which means you only convert 99% of the £ to BRL. */ function convertToBRL(priceB) { - substPercent = (priceB / 99) * 99 ; + substPercent = priceB * .99 ; return substPercent * 5.7; } -console.log(convertToBRL(100.00)); +console.log(convertToBRL(30)); /* ======= TESTS - DO NOT MODIFY ===== There are some Tests in this file that will help you work out if your code is working. @@ -32,7 +32,7 @@ There are some Tests in this file that will help you work out if your code is wo To run these tests type `npm run extraTo run the tests for just this one file, type `npm run extra-tests -- --testPathPattern 1-syntax-errors` into your terminal (Reminder: You must have run `npm install` one time before this will work!) */ -/* + test("convertToUSD function works for £32", () => { expect(convertToUSD(32)).toEqual(44.8); }); @@ -48,4 +48,3 @@ test("convertToBRL function works for £30", () => { test("convertToBRL function works for £1.50", () => { expect(convertToBRL(1.5)).toEqual(8.46); }); -*/ \ No newline at end of file diff --git a/extra/2-piping.js b/extra/2-piping.js index 9c8ebc76a..dd0bca224 100644 --- a/extra/2-piping.js +++ b/extra/2-piping.js @@ -6,7 +6,8 @@ - one that multiplies 2 numbers together - one that formats a number so it's returned as a string with a £ sign before it (e.g. 20 -> £20) - 2. Using the variable startingValue as input, perform the following operations using your functions all + 2. Using the variable startingValue as input, perform the following operations + using your functions all on one line (assign the result to the variable badCode): - add 10 to startingValue - multiply the result by 2 @@ -16,26 +17,43 @@ the final result to the variable goodCode */ -function add() { - +function add(num1, num2) { + return num1 + num2; } -function multiply() { - +function multiply(num1, num2) { + return num1 * num2; } -function format() { - +function format(number) { + return "£" + number; } const startingValue = 2; // Why can this code be seen as bad practice? Comment your answer. -let badCode = +let badCode = format((multiply(add(startingValue,10),2))); //I never think to write this without your help CYF + //Is a bad code I know but I understand what I wrote +console.log(badCode); + + /*BETTER PRACTICE */ + +function performOperations (numToAdd, numToMultiply){ + sum = numToAdd + startingValue; + multiplication = sum * numToMultiply; + return "£" + multiplication; +} + +let goodCode = performOperations(10,2); -/* BETTER PRACTICE */ +console.log(goodCode); +/* £££ UNCOMMENT THIS CODE TO RUN WITH FIXED VALUES $$$ -let goodCode = +function performOperations (){ + sum = 10 + startingValue; + multiplication = sum * 2; + return "£" + multiplication; + */ /* ======= 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/3-magic-8-ball.js b/extra/3-magic-8-ball.js index f3adbefa5..06e3701a6 100644 --- a/extra/3-magic-8-ball.js +++ b/extra/3-magic-8-ball.js @@ -13,15 +13,17 @@ and have different levels of positivity or negativity. Below are the possible answers: - - ## Very positive - It is certain. - It is decidedly so. - Without a doubt. - Yes - definitely. - You may rely on it. - - ## Positive +*/ +let possibleAnswer = new Array (); + possibleAnswer[0] = new Array ( + "Very positive", + "It is certain", + "It is decidedly so", + "Without a doubt", + "Yes - definitely", + "You may rely on it" +); + possibleAnswer[0] = new Array (Positive = ( As I see it, yes. Most likely. Outlook good. @@ -41,14 +43,18 @@ My sources say no. Outlook not so good. Very doubtful. -*/ +] // This should log "The ball has shaken!" // and return the answer. -function shakeBall() { - //Write your code in here +function shakeBall(question) { + console.log("The ball has shaken!"); + let answer = Math.random() * (17 - 5) + 5; + return "did you ask " + question + " ?" ) } +let answer = Math.round(Math.random() * (17 - 5) + 5); +console.log(answer); /* This function should say whether the answer it is given is - very positive diff --git a/mandatory/1-syntax-errors.js b/mandatory/1-syntax-errors.js index a10cc9ac2..f86a01c96 100644 --- a/mandatory/1-syntax-errors.js +++ b/mandatory/1-syntax-errors.js @@ -1,14 +1,14 @@ // 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"; } diff --git a/mandatory/2-logic-error.js b/mandatory/2-logic-error.js index 9cca7603b..fba446374 100644 --- a/mandatory/2-logic-error.js +++ b/mandatory/2-logic-error.js @@ -1,16 +1,15 @@ // The syntax for this function is valid but it has an error, find it and fix it. function trimWord(word) { - return wordtrim(); + return trimWord(); } 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..6eb2ba93d 100644 --- a/mandatory/3-function-output.js +++ b/mandatory/3-function-output.js @@ -1,15 +1,15 @@ // Add comments to explain what this function does. You're meant to use Google! function getRandomNumber() { - return Math.random() * 10; + return Math.random() * 10;///This function does a multiplication of a random number by 10; } // Add comments to explain what this function does. You're meant to use Google! function combine2Words(word1, word2) { - return word1.concat(word2); + return word1.concat(word2); // the concat method convert all into one string any value given. } function concatenate(firstWord, secondWord, thirdWord) { - // Write the body of this function to concatenate three words together. + return firstWord.concat(" ",secondWord).concat(" ",thirdWord); // 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 ba77c7ae2..ba6fca0eb 100644 --- a/mandatory/4-tax.js +++ b/mandatory/4-tax.js @@ -1,12 +1,16 @@ /* SALES TAX ========= - A business requires a program that calculates how much the price of a product is including sales tax + A business requires a program that calculates how much the price of a product + is including sales tax Sales tax is 20% of the price of the product. */ -function calculateSalesTax() {} +function calculateSalesTax(price) { + return ((price * .20) + price); +} +console.log(calculateSalesTax(80)); /* CURRENCY FORMATTING =================== @@ -17,8 +21,12 @@ function calculateSalesTax() {} Remember that the prices must include the sales tax (hint: you already wrote a function for this!) */ -function addTaxAndFormatCurrency() {} - +function addTaxAndFormatCurrency(prices) { + num = calculateSalesTax(prices); + n = num.toFixed(2); + return "£" + n; +} +console.log(addTaxAndFormatCurrency(100)) /* =================================================== ======= TESTS - DO NOT MODIFY BELOW THIS LINE ===== From 0eaa0bae067181c44aacf1f354de0f7e85796f2a Mon Sep 17 00:00:00 2001 From: aalassv Date: Sat, 24 Jul 2021 21:52:16 +0100 Subject: [PATCH 3/3] All done --- mandatory/1-syntax-errors.js | 15 ++++++++++----- mandatory/2-logic-error.js | 4 ++-- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/mandatory/1-syntax-errors.js b/mandatory/1-syntax-errors.js index f86a01c96..7036c3c9e 100644 --- a/mandatory/1-syntax-errors.js +++ b/mandatory/1-syntax-errors.js @@ -4,15 +4,20 @@ 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"; + totalIs = a + b; + return "The total is " + totalIs; } +console.log(addNumbers(123,234,453)); +console.log(introduceMe("Israel",38)); +console.log(getTotal(23,345)); + + /* =================================================== ======= TESTS - DO NOT MODIFY BELOW THIS LINE ===== diff --git a/mandatory/2-logic-error.js b/mandatory/2-logic-error.js index fba446374..b007bc8e0 100644 --- a/mandatory/2-logic-error.js +++ b/mandatory/2-logic-error.js @@ -1,9 +1,8 @@ // The syntax for this function is valid but it has an error, find it and fix it. function trimWord(word) { - return trimWord(); + return trimWord();// I didn't understand what do you want here!!! } - function getStringLength(word) { return word.length(); } @@ -12,6 +11,7 @@ function multiply(a, b, c) { return a * b * c; } + /* =================================================== ======= TESTS - DO NOT MODIFY BELOW THIS LINE =====