From dcf0200b8990861277176e2e324bdf6f21dd53dc Mon Sep 17 00:00:00 2001 From: pezhman azizi Date: Wed, 11 Aug 2021 21:59:22 +0100 Subject: [PATCH 1/2] wm3-pezhman-azizi-javascript-week1 I have made all the changes as required in the read me files --- exercises/B-hello-world/exercise.js | 11 ++++++++++ exercises/C-variables/exercise.js | 6 +++++- 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 | 10 +++++++++ exercises/F-strings-methods/exercise2.js | 20 +++++++++++++++++- exercises/G-numbers/README.md | 2 +- exercises/G-numbers/exercise.js | 9 ++++++++ exercises/I-floats/exercise.js | 21 +++++++++++++++++++ exercises/J-functions/exercise.js | 2 +- exercises/J-functions/exercise2.js | 2 +- exercises/K-functions-parameters/exercise.js | 4 ++-- exercises/K-functions-parameters/exercise2.js | 4 +++- exercises/K-functions-parameters/exercise3.js | 6 ++++-- exercises/K-functions-parameters/exercise4.js | 6 ++++-- exercises/K-functions-parameters/exercise5.js | 5 ++++- exercises/L-functions-nested/exercise.js | 20 ++++++++++++++++++ 18 files changed, 122 insertions(+), 15 deletions(-) diff --git a/exercises/B-hello-world/exercise.js b/exercises/B-hello-world/exercise.js index b179ee953..ec9a3c685 100644 --- a/exercises/B-hello-world/exercise.js +++ b/exercises/B-hello-world/exercise.js @@ -1 +1,12 @@ + + console.log("Hello world"); +console.log("Hello world. I am learning programming and it is so much fun"); +console.log("I have been exercising Java Script and we are in week 1."); +console.log("I am looking forward to learn more and more."); + +//If I get rid of the quotation mark, I face a syntax error and following codes wont operate. + +console.log(123); + +//After fixing the quotation mark from the previous console.log, and console.log a number a number will appear in the terminal in yellow. diff --git a/exercises/C-variables/exercise.js b/exercises/C-variables/exercise.js index a6bbb9786..6c0edf8cc 100644 --- a/exercises/C-variables/exercise.js +++ b/exercises/C-variables/exercise.js @@ -1,3 +1,7 @@ // Start by creating a variable `greeting` - +var greeting = "Hello World"; +console.log(greeting); console.log(greeting); +console.log(greeting); + +// all three results are shown as expected diff --git a/exercises/D-strings/README.md b/exercises/D-strings/README.md index fd0a664ae..2d1623374 100644 --- a/exercises/D-strings/README.md +++ b/exercises/D-strings/README.md @@ -1,6 +1,6 @@ In programming there are different _types of_ data. You've used one data type already: **string**. -Computers recognise strings as a sequence of characters but to humans, strings are simply lines of text. +Computers recognize strings as a sequence of characters but to humans, strings are simply lines of text. ```js var message = "This is a string"; diff --git a/exercises/D-strings/exercise.js b/exercises/D-strings/exercise.js index 2cffa6a81..13af96803 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 = "This is a string. "; console.log(message); +var typeOfMessage = typeof message; +console.log(typeOfMessage); diff --git a/exercises/E-strings-concatenation/exercise.js b/exercises/E-strings-concatenation/exercise.js index 2cffa6a81..4902fc2fd 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 myName = "Pezhman"; +var message = greetingStart + myName; console.log(message); diff --git a/exercises/F-strings-methods/exercise.js b/exercises/F-strings-methods/exercise.js index 2cffa6a81..19c930bad 100644 --- a/exercises/F-strings-methods/exercise.js +++ b/exercises/F-strings-methods/exercise.js @@ -1,3 +1,13 @@ // Start by creating a variable `message` +// EXERCISE ONE: + +var myName = "Pezhman"; +var myNameLength = myName.length; +var message = + "My name is " + + myName + + " and my name is " + + myNameLength + + " characters long."; console.log(message); diff --git a/exercises/F-strings-methods/exercise2.js b/exercises/F-strings-methods/exercise2.js index b4b46943d..64edfdcdd 100644 --- a/exercises/F-strings-methods/exercise2.js +++ b/exercises/F-strings-methods/exercise2.js @@ -1,3 +1,21 @@ -const name = " Daniel "; +const myName = " Daniel "; +// first I wanted to know the length of the given name with space inside quotation mark +const nameLength = myName.length; +console.log(nameLength); //9 + +// I wanna use the .trim function to get rid of the unwanted space +const correctedName = myName.trim(); +const correctedNameLength = correctedName.length; + +console.log(correctedNameLength); //7 + +//Now I type the message + +const message = + "My name is" + + myName + + "and my name is " + + correctedNameLength + + " characters long."; console.log(message); diff --git a/exercises/G-numbers/README.md b/exercises/G-numbers/README.md index 76a79dab2..6b5ba8dfd 100644 --- a/exercises/G-numbers/README.md +++ b/exercises/G-numbers/README.md @@ -6,7 +6,7 @@ Unlike strings, numbers do not need to be wrapped in quotes. var age = 30; ``` -You can use mathematical operators to caclulate numbers: +You can use mathematical operators to calculate numbers: ```js var sum = 10 + 2; // 12 diff --git a/exercises/G-numbers/exercise.js b/exercises/G-numbers/exercise.js index 49e7bc00b..225c496e2 100644 --- a/exercises/G-numbers/exercise.js +++ b/exercises/G-numbers/exercise.js @@ -1 +1,10 @@ // Start by creating a variables `numberOfStudents` and `numberOfMentors` +let numberOfStudents = 15; +let numberOfMentors = 8; +let total = numberOfStudents + numberOfMentors; + +let percentageOfStudents = numberOfStudents / total; +let percentageOfMentors = numberOfMentors / total; + +console.log(percentageOfStudents); +console.log(percentageOfMentors); diff --git a/exercises/I-floats/exercise.js b/exercises/I-floats/exercise.js index a5bbcd852..155bb51c6 100644 --- a/exercises/I-floats/exercise.js +++ b/exercises/I-floats/exercise.js @@ -1,2 +1,23 @@ var numberOfStudents = 15; var numberOfMentors = 8; +var total = numberOfStudents + numberOfMentors; + +//percentage before rounding up and showing them in console +var percentageOfStudents = (numberOfStudents / total) * 100; +var percentageOfMentors = (numberOfMentors / total) * 100; + +console.log(percentageOfStudents); +console.log(percentageOfMentors); + +//Rounding up percentages and showing them on console +var roundPercStudents = Math.round(percentageOfStudents); +var roundPercMentors = Math.round(percentageOfMentors); +console.log(roundPercStudents); +console.log(roundPercMentors); + +//Declaring sentences by a string variable and showing them to the console +const studentResult = "Percentage of students is: " + roundPercStudents; +const mentorsResult = "Percentage of mentors is: " + roundPercMentors; + +console.log(studentResult); +console.log(mentorsResult); diff --git a/exercises/J-functions/exercise.js b/exercises/J-functions/exercise.js index 0ae5850e5..22d2db355 100644 --- a/exercises/J-functions/exercise.js +++ b/exercises/J-functions/exercise.js @@ -1,5 +1,5 @@ function halve(number) { - // complete the function here + return number / 2; // complete the function here } var result = halve(12); diff --git a/exercises/J-functions/exercise2.js b/exercises/J-functions/exercise2.js index 82ef5e780..6cd65c011 100644 --- a/exercises/J-functions/exercise2.js +++ b/exercises/J-functions/exercise2.js @@ -1,5 +1,5 @@ function triple(number) { - // complete function here + return number * 3; // complete function here } var result = triple(12); diff --git a/exercises/K-functions-parameters/exercise.js b/exercises/K-functions-parameters/exercise.js index 8d5db5e69..676cf35aa 100644 --- a/exercises/K-functions-parameters/exercise.js +++ b/exercises/K-functions-parameters/exercise.js @@ -1,6 +1,6 @@ // 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` diff --git a/exercises/K-functions-parameters/exercise2.js b/exercises/K-functions-parameters/exercise2.js index db7a8904b..8f0f0680b 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); console.log(result); diff --git a/exercises/K-functions-parameters/exercise3.js b/exercises/K-functions-parameters/exercise3.js index 537e9f4ec..6706da833 100644 --- a/exercises/K-functions-parameters/exercise3.js +++ b/exercises/K-functions-parameters/exercise3.js @@ -1,5 +1,7 @@ // Write your function here - -var greeting = createGreeting("Daniel"); +function createGreeting(name) { + return name; +} +var greeting = "my name is: " + createGreeting("Daniel"); console.log(greeting); diff --git a/exercises/K-functions-parameters/exercise4.js b/exercises/K-functions-parameters/exercise4.js index 7ab44589e..ac2f47647 100644 --- a/exercises/K-functions-parameters/exercise4.js +++ b/exercises/K-functions-parameters/exercise4.js @@ -1,5 +1,7 @@ // Declare your function first +function add(num1, num2) { + return num1 + num2; +} -// Call the function and assign to a variable `sum` - +var sum = add(13, 124); // Call the function and assign to a variable `sum` console.log(sum); diff --git a/exercises/K-functions-parameters/exercise5.js b/exercises/K-functions-parameters/exercise5.js index 7c5bcd605..097491b03 100644 --- a/exercises/K-functions-parameters/exercise5.js +++ b/exercises/K-functions-parameters/exercise5.js @@ -1,5 +1,8 @@ // Declare your function here - +function createLongGreeting(name, age) { + const greetings = `My name is ${name} and I'm ${age} years old.`; + return greetings; +} const greeting = createLongGreeting("Daniel", 30); console.log(greeting); diff --git a/exercises/L-functions-nested/exercise.js b/exercises/L-functions-nested/exercise.js index a5d377442..da1218b83 100644 --- a/exercises/L-functions-nested/exercise.js +++ b/exercises/L-functions-nested/exercise.js @@ -3,3 +3,23 @@ var mentor2 = "Irina"; var mentor3 = "Mimi"; var mentor4 = "Rob"; var mentor5 = "Yohannes"; + +function shouty(mentor) { + var upperCaseMentor = mentor.toUpperCase(); + return `HELLO ${upperCaseMentor}`; +} + +var shoutyGreeting = shouty(mentor1); +console.log(shoutyGreeting); + +var shoutyGreeting = shouty(mentor2); +console.log(shoutyGreeting); + +var shoutyGreeting = shouty(mentor3); +console.log(shoutyGreeting); + +var shoutyGreeting = shouty(mentor4); +console.log(shoutyGreeting); + +var shoutyGreeting = shouty(mentor5); +console.log(shoutyGreeting); From 5cbd866e31db3dbd98b8f106c5306782f3d05540 Mon Sep 17 00:00:00 2001 From: pezhman azizi Date: Thu, 12 Aug 2021 17:41:03 +0100 Subject: [PATCH 2/2] wm3-pezhman-azizi-javascript-week1 All the tests are passed --- mandatory/1-syntax-errors.js | 13 ++++++++----- mandatory/2-logic-error.js | 7 +++---- mandatory/3-function-output.js | 4 +++- mandatory/4-tax.js | 16 ++++++++++++++-- 4 files changed, 28 insertions(+), 12 deletions(-) diff --git a/mandatory/1-syntax-errors.js b/mandatory/1-syntax-errors.js index a10cc9ac2..ca08417cc 100644 --- a/mandatory/1-syntax-errors.js +++ b/mandatory/1-syntax-errors.js @@ -1,16 +1,19 @@ // 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; } +totalNum = addNumbers(1, 2, 3); +console.log(totalNum); -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; + 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..f070b7ec2 100644 --- a/mandatory/3-function-output.js +++ b/mandatory/3-function-output.js @@ -1,6 +1,8 @@ // Add comments to explain what this function does. You're meant to use Google! + +//this function chooses a random number below 1: function getRandomNumber() { - return Math.random() * 10; + return Math.floor(Math.random() * 10); } // Add comments to explain what this function does. You're meant to use Google! diff --git a/mandatory/4-tax.js b/mandatory/4-tax.js index ba77c7ae2..9434fbca2 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) { + return price * 0.2; +} + +//let percentage = calculateSalesTax(15); +//console.log(percentage); /* CURRENCY FORMATTING @@ -17,7 +22,14 @@ function calculateSalesTax() {} Remember that the prices must include the sales tax (hint: you already wrote a function for this!) */ -function addTaxAndFormatCurrency() {} +function addTaxAndFormatCurrency(price) { + let result = price + calculateSalesTax(price); + let poundFormat = result.toFixed(2); + return `£${poundFormat}`; +} + +console.log(calculateSalesTax(17.5)); +console.log(addTaxAndFormatCurrency(17.5)); /* ===================================================