From 5619a990b054a0fcb461ade805f9fa287800c3de Mon Sep 17 00:00:00 2001 From: hanakisu <105117072+hanakisu@users.noreply.github.com> Date: Fri, 5 Aug 2022 21:10:15 +0100 Subject: [PATCH 1/2] javaweek1 --- exercises/B-hello-world/exercise.js | 10 +++++++++- exercises/C-variables/exercise.js | 7 ++++++- exercises/D-strings/exercise.js | 5 +++-- exercises/E-strings-concatenation/exercise.js | 5 ++++- exercises/F-strings-methods/exercise.js | 10 ++++++++-- exercises/F-strings-methods/exercise2.js | 11 +++++++++-- exercises/G-numbers/exercise.js | 4 ++++ exercises/I-floats/exercise.js | 9 +++++++-- exercises/J-functions/exercise.js | 1 + exercises/J-functions/exercise2.js | 1 + exercises/K-functions-parameters/exercise.js | 3 ++- exercises/K-functions-parameters/exercise2.js | 5 ++++- exercises/K-functions-parameters/exercise3.js | 5 ++++- exercises/K-functions-parameters/exercise4.js | 10 +++++++++- exercises/K-functions-parameters/exercise5.js | 7 ++++++- exercises/L-functions-nested/exercise.js | 8 ++++++++ extra/1-currency-conversion.js | 6 +++++- mandatory/1-syntax-errors.js | 18 ++++++++++++------ mandatory/2-logic-error.js | 7 +++---- mandatory/3-function-output.js | 9 +++++++-- mandatory/4-tax.js | 13 ++++++++++--- 21 files changed, 122 insertions(+), 32 deletions(-) diff --git a/exercises/B-hello-world/exercise.js b/exercises/B-hello-world/exercise.js index b179ee953..0d6087a4c 100644 --- a/exercises/B-hello-world/exercise.js +++ b/exercises/B-hello-world/exercise.js @@ -1 +1,9 @@ -console.log("Hello world"); +let greeting = "Hello world"; +console.log(greeting); +greeting2 = "I just started learning JavaScript!" +console.log(greeting2); +greeting3 = "My aim is to understand the bacis" +console.log(greeting3); + const value = 31 +console.log(value) + diff --git a/exercises/C-variables/exercise.js b/exercises/C-variables/exercise.js index a6bbb9786..0bf174e29 100644 --- a/exercises/C-variables/exercise.js +++ b/exercises/C-variables/exercise.js @@ -1,3 +1,8 @@ // Start by creating a variable `greeting` - + greeting = "Hello word" console.log(greeting); +greeting2 = "Hello word" +console.log(greeting2) +greeting3 = "Hello word" +console.log(greeting3) + diff --git a/exercises/D-strings/exercise.js b/exercises/D-strings/exercise.js index 2cffa6a81..8dac9a32a 100644 --- a/exercises/D-strings/exercise.js +++ b/exercises/D-strings/exercise.js @@ -1,3 +1,4 @@ // Start by creating a variable `message` - -console.log(message); +let message = "This is a string" +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..f0ebe0e6e 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` - +let greeting = "Hello, my name is" +let name = "seble" +message = greeting + " " + name + "."; console.log(message); + diff --git a/exercises/F-strings-methods/exercise.js b/exercises/F-strings-methods/exercise.js index 2cffa6a81..18ddc2b41 100644 --- a/exercises/F-strings-methods/exercise.js +++ b/exercises/F-strings-methods/exercise.js @@ -1,3 +1,9 @@ // Start by creating a variable `message` - -console.log(message); +let name = "Seble" +console.log(name.length) // Logs 5 +console.log(name.toLowerCase()) // "sebel" +let greeting = "Hello, my name is" +let myName = "Seble" +let message = "and my name is 5 characters long" +myChar = greeting + " " + myName + " " + message +console.log(myChar) diff --git a/exercises/F-strings-methods/exercise2.js b/exercises/F-strings-methods/exercise2.js index b4b46943d..f2b978558 100644 --- a/exercises/F-strings-methods/exercise2.js +++ b/exercises/F-strings-methods/exercise2.js @@ -1,3 +1,10 @@ -const name = " Daniel "; +const name = " Seble "; +let none = name +console.log(none.trim()) -console.log(message); + +let greeting = "Hello, my name is" +let myName = "Seble" +let message = "and my name is 5 characters long" +myChar = greeting + " " + myName + " " + message +console.log(myChar) diff --git a/exercises/G-numbers/exercise.js b/exercises/G-numbers/exercise.js index 49e7bc00b..aac040cad 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) \ No newline at end of file diff --git a/exercises/I-floats/exercise.js b/exercises/I-floats/exercise.js index a5bbcd852..84b4ba58b 100644 --- a/exercises/I-floats/exercise.js +++ b/exercises/I-floats/exercise.js @@ -1,2 +1,7 @@ -var numberOfStudents = 15; -var numberOfMentors = 8; +let numberOfStudents = 15; +let numberOfMentors = 8; +let total = numberOfStudents + numberOfMentors + let studentsPercentage = numberOfStudents / total * 100 + console.log(Math.round(studentsPercentage) + "%") +let mentorsPercentage = (numberOfMentors * 100) / total + console.log(Math.round(mentorsPercentage) + "%") diff --git a/exercises/J-functions/exercise.js b/exercises/J-functions/exercise.js index 0ae5850e5..ae32ae2dc 100644 --- a/exercises/J-functions/exercise.js +++ b/exercises/J-functions/exercise.js @@ -1,4 +1,5 @@ function halve(number) { + return (12 / 2) // complete the function here } diff --git a/exercises/J-functions/exercise2.js b/exercises/J-functions/exercise2.js index 82ef5e780..413f2f6ca 100644 --- a/exercises/J-functions/exercise2.js +++ b/exercises/J-functions/exercise2.js @@ -1,4 +1,5 @@ function triple(number) { + return (12 * 3) // complete function here } diff --git a/exercises/K-functions-parameters/exercise.js b/exercises/K-functions-parameters/exercise.js index 8d5db5e69..3689e8829 100644 --- a/exercises/K-functions-parameters/exercise.js +++ b/exercises/K-functions-parameters/exercise.js @@ -1,9 +1,10 @@ // Complete the function so that it takes input parameters function multiply() { + return (3 * 4) // Calculate the result of the function and return it } // 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..d340acca8 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() { + return(3 / 4) +} -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..a4de96e93 100644 --- a/exercises/K-functions-parameters/exercise3.js +++ b/exercises/K-functions-parameters/exercise3.js @@ -1,5 +1,8 @@ // Write your function here +function createGreeting(name) { + return greeting = `Hello, my name is ${name}` +} -var greeting = createGreeting("Daniel"); + greeting = createGreeting("seble"); console.log(greeting); diff --git a/exercises/K-functions-parameters/exercise4.js b/exercises/K-functions-parameters/exercise4.js index 7ab44589e..1ce3e5128 100644 --- a/exercises/K-functions-parameters/exercise4.js +++ b/exercises/K-functions-parameters/exercise4.js @@ -1,5 +1,13 @@ // Declare your function first // Call the function and assign to a variable `sum` +function passing(a, b) { + return sum = a + b; +} + +// Call the function and assign to a variable `sum` + sum = passing(13, 124) + +console.log(sum); + -console.log(sum); diff --git a/exercises/K-functions-parameters/exercise5.js b/exercises/K-functions-parameters/exercise5.js index 7c5bcd605..1a1b651b8 100644 --- a/exercises/K-functions-parameters/exercise5.js +++ b/exercises/K-functions-parameters/exercise5.js @@ -1,5 +1,10 @@ // Declare your function here +function createLongGreeting(myName, greeting, Age) { + return("Hello, my name is", myName,"and I'm", Age;) + +} +//Hello, my name is Daniel and I'm 30 years old const greeting = createLongGreeting("Daniel", 30); -console.log(greeting); +console.log(greeting) diff --git a/exercises/L-functions-nested/exercise.js b/exercises/L-functions-nested/exercise.js index a5d377442..94a6296f6 100644 --- a/exercises/L-functions-nested/exercise.js +++ b/exercises/L-functions-nested/exercise.js @@ -3,3 +3,11 @@ var mentor2 = "Irina"; var mentor3 = "Mimi"; var mentor4 = "Rob"; var mentor5 = "Yohannes"; +function mentors(name) { + return `HELLO ${name.toUppreCase()}!` +} +console.log(mentors(mentor1)) +console.log(mentors(mentor2)) +console.log(mentors(mentor3)) +console.log(mentors(mentor4)) +console.log(mentors(mentor5)) \ No newline at end of file diff --git a/extra/1-currency-conversion.js b/extra/1-currency-conversion.js index 75b3c6aab..6f4f1c1d6 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() { + + +} +console.log(convertToUSD) /* CURRENCY CONVERSION diff --git a/mandatory/1-syntax-errors.js b/mandatory/1-syntax-errors.js index a10cc9ac2..6afac3ad7 100644 --- a/mandatory/1-syntax-errors.js +++ b/mandatory/1-syntax-errors.js @@ -1,16 +1,22 @@ // There are syntax errors in this code - can you fix it to pass the tests? -function addNumbers(a b c) { - return 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"; + +} +console.log(introduceMe("Sonjide", 27)) 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 9cca7603b..37c4ebc15 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 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..57b5099a8 100644 --- a/mandatory/3-function-output.js +++ b/mandatory/3-function-output.js @@ -1,17 +1,22 @@ // Add comments to explain what this function does. You're meant to use Google! function getRandomNumber() { - return Math.random() * 10; + return Math.random() * 10; // random numbers are 0 or less than 1 so multiplying by 10 and gives as a random number. } + +console.log(getRandomNumber) // 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); //When a function is defined, it is typically defined along with one or more parameters. + //The actual values that are input (or "passed") into a function when it is called are known as arguments. } 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. + console.log(firstWord, secondWord, thirdWord) } +concatenate(I, am, 13) /* =================================================== diff --git a/mandatory/4-tax.js b/mandatory/4-tax.js index ba77c7ae2..a5639ab55 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) { + let salesTax = (price * 20) / 100; + let totalPrice = price + salesTax; + return totalPrice; + +} /* CURRENCY FORMATTING @@ -17,8 +22,10 @@ function calculateSalesTax() {} Remember that the prices must include the sales tax (hint: you already wrote a function for this!) */ -function addTaxAndFormatCurrency() {} - +function addTaxAndFormatCurrency(amount) { + return `£${calculateSalesTax(amount).toFixed(2)}`; +} +console.log(addTaxAndFormatCurrency(17.5)); /* =================================================== ======= TESTS - DO NOT MODIFY BELOW THIS LINE ===== From 066a3919054b2209b5029e0fa10fb80a06a5c18b Mon Sep 17 00:00:00 2001 From: hanakisu <105117072+hanakisu@users.noreply.github.com> Date: Sun, 7 Aug 2022 13:25:35 +0100 Subject: [PATCH 2/2] all problem solve --- mandatory/1-syntax-errors.js | 2 +- mandatory/3-function-output.js | 4 ++-- mandatory/4-tax.js | 14 +++++++------- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/mandatory/1-syntax-errors.js b/mandatory/1-syntax-errors.js index 6afac3ad7..b97106128 100644 --- a/mandatory/1-syntax-errors.js +++ b/mandatory/1-syntax-errors.js @@ -11,7 +11,7 @@ function introduceMe(name, age) { return "Hello, my name is " + name + " and I am " + age + " years old"; } -console.log(introduceMe("Sonjide", 27)) +console.log(introduceMe("dan", 17)) function getTotal(a, b) { let total = a + b; diff --git a/mandatory/3-function-output.js b/mandatory/3-function-output.js index 57b5099a8..b2a8d2183 100644 --- a/mandatory/3-function-output.js +++ b/mandatory/3-function-output.js @@ -14,9 +14,9 @@ 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. - console.log(firstWord, secondWord, thirdWord) + return firstWord + " " + secondWord + " " + thirdWord } -concatenate(I, am, 13) + /* =================================================== diff --git a/mandatory/4-tax.js b/mandatory/4-tax.js index a5639ab55..7a3b038f9 100644 --- a/mandatory/4-tax.js +++ b/mandatory/4-tax.js @@ -5,10 +5,9 @@ Sales tax is 20% of the price of the product. */ -function calculateSalesTax(price) { - let salesTax = (price * 20) / 100; - let totalPrice = price + salesTax; - return totalPrice; +function calculateSalesTax(priceBefore) { + + return priceBefore + (priceBefore * 20) / 100; } @@ -22,10 +21,11 @@ function calculateSalesTax(price) { Remember that the prices must include the sales tax (hint: you already wrote a function for this!) */ -function addTaxAndFormatCurrency(amount) { - return `£${calculateSalesTax(amount).toFixed(2)}`; +function addTaxAndFormatCurrency(priceBefore) { + let priceAfter = calculateSalesTax(priceBefore); + return `£${priceAfter.toFixed(2)}`; } -console.log(addTaxAndFormatCurrency(17.5)); + /* =================================================== ======= TESTS - DO NOT MODIFY BELOW THIS LINE =====