diff --git a/exercises/B-hello-world/exercise.js b/exercises/B-hello-world/exercise.js index b179ee953..3419049a6 100644 --- a/exercises/B-hello-world/exercise.js +++ b/exercises/B-hello-world/exercise.js @@ -1 +1,9 @@ -console.log("Hello world"); + +console.log("hello world"); +console.log("I just started learning JavaScript!"); +console.log("hi"); + + + + + diff --git a/exercises/C-variables/exercise.js b/exercises/C-variables/exercise.js index a6bbb9786..91e425647 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 = "Hey! I am a variable"; +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..d8d1e3cea 100644 --- a/exercises/D-strings/exercise.js +++ b/exercises/D-strings/exercise.js @@ -1,3 +1,5 @@ // Start by creating a variable `message` -console.log(message); +let message = "this is text inside ' ' and the name is string" +console.log(typeof message); + diff --git a/exercises/E-strings-concatenation/exercise.js b/exercises/E-strings-concatenation/exercise.js index 2cffa6a81..ac16782be 100644 --- a/exercises/E-strings-concatenation/exercise.js +++ b/exercises/E-strings-concatenation/exercise.js @@ -1,3 +1,12 @@ // Start by creating a variable `message` +let students = "we are seven students"; + +let teacher = " and 2 teachers"; + +let message = students + teacher + " working in the proyect."; + + + + console.log(message); diff --git a/exercises/F-strings-methods/exercise.js b/exercises/F-strings-methods/exercise.js index 2cffa6a81..0dcab2887 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); +let message = " tell me how many words I am; "; +let stringLength = message.length; +console.log(message + "the length is: " + stringLength); diff --git a/exercises/F-strings-methods/exercise2.js b/exercises/F-strings-methods/exercise2.js index b4b46943d..cc4bb7d86 100644 --- a/exercises/F-strings-methods/exercise2.js +++ b/exercises/F-strings-methods/exercise2.js @@ -1,3 +1,6 @@ -const name = " Daniel "; +const myname = "Karla"; -console.log(message); +let CharactersLength = myname.length; + + +console.log(`my name is ${CharactersLength} characters`); //to make the interpolation is alwais the backticks diff --git a/exercises/G-numbers/README.md b/exercises/G-numbers/README.md index 6775ad18f..dbe5ef4b5 100644 --- a/exercises/G-numbers/README.md +++ b/exercises/G-numbers/README.md @@ -10,13 +10,14 @@ You can use mathematical operators to caclulate numbers: ```js var sum = 10 + 2; // 12 -var product = 10 * 2; // 20 +var product = 10 * 2; // 20 var quotient = 10 / 2; // 5 var difference = 10 - 2; // 8 ``` ## Exercise + - Create two variables `numberOfStudents` and `numberOfMentors` - Log a message that displays the total number of students and mentors diff --git a/exercises/G-numbers/exercise.js b/exercises/G-numbers/exercise.js index 49e7bc00b..e58751311 100644 --- a/exercises/G-numbers/exercise.js +++ b/exercises/G-numbers/exercise.js @@ -1 +1,9 @@ -// Start by creating a variables `numberOfStudents` and `numberOfMentors` +// Start by creating a variables +// `numberOfStudents` and `numberOfMentors` + +let numberOfStudents = 15; +let numberOfMentors = 8; + +let total = numberOfStudents + numberOfMentors; + +console.log(`total number of studentes and mentor: ${total}`); \ No newline at end of file diff --git a/exercises/I-floats/README.md b/exercises/I-floats/README.md index bbc9e29c2..093190a4b 100644 --- a/exercises/I-floats/README.md +++ b/exercises/I-floats/README.md @@ -1,8 +1,8 @@ Numbers can be integers (whole numbers) or floats (numbers with a decimal). ```js -var preciseAge = 30.612437; -``` +var preciseAge = 30.612437; //float number +``` Floats can be rounded to the nearest whole number using the `Math.round` function: diff --git a/exercises/I-floats/exercise.js b/exercises/I-floats/exercise.js index a5bbcd852..5f2bff255 100644 --- a/exercises/I-floats/exercise.js +++ b/exercises/I-floats/exercise.js @@ -1,2 +1,13 @@ -var numberOfStudents = 15; -var numberOfMentors = 8; +let numberOfStudents = 15; +let numberOfMentors = 8; + +let total = numberOfStudents + numberOfMentors; + +console.log(`total number of studentes and mentor: ${total}`); + +let porcentage = (numberOfStudents/total ) * 100; //here we did the average and the number return float +let porcentageB = (numberOfMentors/total ) * 100; + +console.log(`Porcentage students ${Math.round(porcentage)}%`);// here we use the comand Math.round to make it again integer and we added % + +console.log(`Porcentage Mentors ${Math.round(porcentageB)}%`); diff --git a/exercises/K-functions-parameters/exercise.js b/exercises/K-functions-parameters/exercise.js index 8d5db5e69..962269212 100644 --- a/exercises/K-functions-parameters/exercise.js +++ b/exercises/K-functions-parameters/exercise.js @@ -1,8 +1,10 @@ // 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` var result = multiply(3, 4); diff --git a/exercises/K-functions-parameters/exercise2.js b/exercises/K-functions-parameters/exercise2.js index db7a8904b..358929754 100644 --- a/exercises/K-functions-parameters/exercise2.js +++ b/exercises/K-functions-parameters/exercise2.js @@ -1,4 +1,7 @@ // Declare your function first +function divide(a, b){ + return a/b; +} var result = divide(3, 4); diff --git a/exercises/K-functions-parameters/exercise3.js b/exercises/K-functions-parameters/exercise3.js index 537e9f4ec..9528c26c6 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(a){ + return "hell, my name is " + a; +} var greeting = createGreeting("Daniel"); diff --git a/exercises/K-functions-parameters/exercise4.js b/exercises/K-functions-parameters/exercise4.js index 7ab44589e..60a22ee17 100644 --- a/exercises/K-functions-parameters/exercise4.js +++ b/exercises/K-functions-parameters/exercise4.js @@ -1,5 +1,9 @@ // Declare your function first +function totalSum(a, b){ + return a + b; +} // Call the function and assign to a variable `sum` +let sum = totalSum(13, 124); console.log(sum); diff --git a/exercises/K-functions-parameters/exercise5.js b/exercises/K-functions-parameters/exercise5.js index 7c5bcd605..fdacc4688 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(a, b){ + return `hello, my name is ${a} and I'm ${b} year old`; +} const greeting = createLongGreeting("Daniel", 30); diff --git a/exercises/L-functions-nested/exercise.js b/exercises/L-functions-nested/exercise.js index a5d377442..998eb8cd7 100644 --- a/exercises/L-functions-nested/exercise.js +++ b/exercises/L-functions-nested/exercise.js @@ -3,3 +3,18 @@ var mentor2 = "Irina"; var mentor3 = "Mimi"; var mentor4 = "Rob"; var mentor5 = "Yohannes"; + + +function convertNameToUpperCase(name) { + return name.toUpperCase(); +} + +function createGreeting(name) { + return `HELLO ${convertNameToUpperCase(name)}`; +} + +console.log(createGreeting(mentor1)); +console.log(createGreeting(mentor2)); +console.log(createGreeting(mentor3)); +console.log(createGreeting(mentor4)); +console.log(createGreeting(mentor5)); \ No newline at end of file diff --git a/mandatory/1-syntax-errors.js b/mandatory/1-syntax-errors.js index a10cc9ac2..67a4ef3da 100644 --- a/mandatory/1-syntax-errors.js +++ b/mandatory/1-syntax-errors.js @@ -1,18 +1,22 @@ // 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 total"; +function getTotal(a, b){ + let total = a + b; + return `The total is ${total}`; //this line we combin + } + /* =================================================== ======= TESTS - DO NOT MODIFY BELOW THIS LINE ===== diff --git a/mandatory/2-logic-error.js b/mandatory/2-logic-error.js index 9cca7603b..c0472ecb0 100644 --- a/mandatory/2-logic-error.js +++ b/mandatory/2-logic-error.js @@ -1,16 +1,26 @@ // The syntax for this function is valid but it has an error, find it and fix it. -function trimWord(word) { - return wordtrim(); +//in this exercise we use the mothod .trim() which help to eliminate leading and trailing spaces. + +function trimWord(phrase) { + let string = phrase.trim(); + return string; } -function getStringLength(word) { - return "word".length(); +// the function .length will show the number of the string that we give by the parameter a +// we created a local variable where we store the result of the parameter + +function getStringLength(a) { + let total = a.length; + return total; } + +//we declared a variable total to store the math operation then we sent the result in the return; + function multiply(a, b, c) { - a * b * c; - return; + let total = a * b * c; + return total; } /* diff --git a/mandatory/3-function-output.js b/mandatory/3-function-output.js index 5a953ba60..97f8ebc88 100644 --- a/mandatory/3-function-output.js +++ b/mandatory/3-function-output.js @@ -1,16 +1,24 @@ // Add comments to explain what this function does. You're meant to use Google! + + +// this function generate a ramdom number between 0 to one number less than the maximun +// which we sent in the parametre. so we wil get from 0 to 9 function getRandomNumber() { - return Math.random() * 10; + return Math.random( ) * 10; } +// console.log(getRandomNumber(10)) // Add comments to explain what this function does. You're meant to use Google! +//This function will combine two parametres in the same line function combine2Words(word1, word2) { return word1.concat(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. +// 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(" " + secondWord + " ").concat(thirdWord); + //we create the spaces that required with the " " and .concat help to join the parametres } /* diff --git a/mandatory/4-tax.js b/mandatory/4-tax.js index ba77c7ae2..7f7d068b9 100644 --- a/mandatory/4-tax.js +++ b/mandatory/4-tax.js @@ -5,9 +5,15 @@ Sales tax is 20% of the price of the product. */ -function calculateSalesTax() {} +function calculateSalesTax(price) { + let porcentage = price * 0.20; //we multiply with 0.20 to obtain the porcentage which + //will be included in the final price. + porcentage += price; + return porcentage; +} -/* + +/* CURRENCY FORMATTING =================== The business has informed you that prices must have 2 decimal places @@ -16,9 +22,14 @@ function calculateSalesTax() {} Remember that the prices must include the sales tax (hint: you already wrote a function for this!) */ +// let calculateSalestax = calculateSalestax; -function addTaxAndFormatCurrency() {} - +function addTaxAndFormatCurrency(price) { + let finalPrice = `£${calculateSalesTax(price).toFixed(2)}`; + //we create a new variable and call the previus function and concatenate with £ and + // .toFixed will give us 2 digits to appear after the decimal point. + return finalPrice; +} /* =================================================== ======= TESTS - DO NOT MODIFY BELOW THIS LINE ===== diff --git a/package.json b/package.json index 93e0861e3..9e7f2ffeb 100644 --- a/package.json +++ b/package.json @@ -14,15 +14,21 @@ "url": "https://github.com/CodeYourFuture/JavaScript-Core-1-Coursework-Week1/issues" }, "jest": { - "setupFilesAfterEnv": ["jest-extended"], + "setupFilesAfterEnv": [ + "jest-extended" + ], "projects": [ { "displayName": "mandatory", - "testMatch": ["/mandatory/*.js"] + "testMatch": [ + "/mandatory/*.js" + ] }, { "displayName": "extra", - "testMatch": ["/extra/*.js"] + "testMatch": [ + "/extra/*.js" + ] } ] },