diff --git a/week-1/Extra/1-syntax-errors.js b/week-1/Extra/1-syntax-errors.js index fb756b63..39e34884 100644 --- a/week-1/Extra/1-syntax-errors.js +++ b/week-1/Extra/1-syntax-errors.js @@ -1,17 +1,18 @@ // 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; + total = a + b; // Use string interpolation here - return "The total is %{total}" + return `The total is ${total}` } /* ======= TESTS - DO NOT MODIFY ===== diff --git a/week-1/Extra/2-logic-error.js b/week-1/Extra/2-logic-error.js index c8444605..71118b8e 100644 --- a/week-1/Extra/2-logic-error.js +++ b/week-1/Extra/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 getWordLength(word) { - return "word".length() + return word.length; } function multiply(a, b, c) { - a * b * c; - return; + return a * b * c; } /* ======= TESTS - DO NOT MODIFY ===== diff --git a/week-1/Extra/3-function-output.js b/week-1/Extra/3-function-output.js index c8e85770..8ee76554 100644 --- a/week-1/Extra/3-function-output.js +++ b/week-1/Extra/3-function-output.js @@ -2,15 +2,19 @@ function getNumber() { return Math.random() * 10; } +// Math.random returns a random number between 0 (inclusive), and 1 (exclusive). But, in this case, this number will be multiplied by 10. Then this function will return a number between 0 and 10(exclusive). + // Add comments to explain what this function does. You're meant to use Google! function s(w1, w2) { return w1.concat(w2); } +// return new element with w1 and w2 concatenated. 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(` `,secondWord, ` `,thirdWord); } /* ======= TESTS - DO NOT MODIFY ===== diff --git a/week-1/Extra/4-tax.js b/week-1/Extra/4-tax.js index 79db5409..53cacf22 100644 --- a/week-1/Extra/4-tax.js +++ b/week-1/Extra/4-tax.js @@ -5,7 +5,11 @@ Sales tax is 20% of the price of the product */ -function calculateSalesTax() {} +function calculateSalesTax(originalPrice) { + let tax = originalPrice*0.2; + let taxPrice = originalPrice+tax; + return taxPrice; +} /* CURRENCY FORMATTING @@ -17,7 +21,10 @@ 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 decimalPrice = calculateSalesTax(price).toFixed(2); + return `£${decimalPrice}`; +} /* ======= 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/week-1/Extra/5-currency-conversion.js b/week-1/Extra/5-currency-conversion.js index 5f060972..d1e9711a 100644 --- a/week-1/Extra/5-currency-conversion.js +++ b/week-1/Extra/5-currency-conversion.js @@ -5,7 +5,9 @@ Write a function that converts a price to USD (exchange rate is 1.4 $ to £) */ -function convertToUSD() {} +function convertToUSD(price) { + return price*1.4 +} /* CURRENCY FORMATTING @@ -15,7 +17,9 @@ 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(price) { + return (0.99*price)*5.7; +} /* ======= 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/week-1/Extra/6-piping.js b/week-1/Extra/6-piping.js index 067dd0f5..3a58eff8 100644 --- a/week-1/Extra/6-piping.js +++ b/week-1/Extra/6-piping.js @@ -16,26 +16,32 @@ the final result to the variable goodCode */ -function add() { - +function add(x,y) { + return x+y; } -function multiply() { - +function multiply(x,y) { + return x*y; } -function format() { - +function format(x) { + return `£${x.toString()}` } const startingValue = 2 // Why can this code be seen as bad practice? Comment your answer. -let badCode = +let badCode = format((startingValue+10)*2); /* BETTER PRACTICE */ -let goodCode = +function toGoodCode(number) { + let operation = (number+10)*2; + let resultFormated = format(operation); + return resultFormated; +} + +let goodCode = toGoodCode(startingValue); /* ======= 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/week-1/Extra/7-magic-8-ball.js b/week-1/Extra/7-magic-8-ball.js index edb75fe6..ff7b5782 100644 --- a/week-1/Extra/7-magic-8-ball.js +++ b/week-1/Extra/7-magic-8-ball.js @@ -46,6 +46,8 @@ Very doubtful. // This should log "The ball has shaken!" // and return the answer. function shakeBall() { + console.log(`The ball has shaken!`) + return `It is certain.`; } // This function should say whether the answer it is given is @@ -55,6 +57,7 @@ function shakeBall() { // - very negative // This function should expect to be called with any value which was returned by the shakeBall function. function checkAnswer(answer) { + } /* ======= TESTS - DO NOT MODIFY ===== diff --git a/week-1/Homework/F-strings-methods/exercise.js b/week-1/Homework/F-strings-methods/exercise.js index 2cffa6a8..cb9f0b7b 100644 --- a/week-1/Homework/F-strings-methods/exercise.js +++ b/week-1/Homework/F-strings-methods/exercise.js @@ -1,3 +1,11 @@ // Start by creating a variable `message` +// let message = 'Amanda' +// console.log(message); + +function lengthMessage(message) { + let lengthMessage = message.length; + console.log(`My name is ${message} ant the length of my name is ${lengthMessage}.`); +} + +lengthMessage("amanda"); -console.log(message); diff --git a/week-1/Homework/F-strings-methods/exercise2.js b/week-1/Homework/F-strings-methods/exercise2.js index b4b46943..68d3d2f5 100644 --- a/week-1/Homework/F-strings-methods/exercise2.js +++ b/week-1/Homework/F-strings-methods/exercise2.js @@ -1,3 +1,9 @@ -const name = " Daniel "; +const names = " Amanda "; +const nameWithTrim = names.trim(); +let lengthNames = names.length; +console.log(names); +console.log(nameWithTrim); + +console.log(`My name is ${nameWithTrim} ant the length of my name is ${lengthNames}.`) + -console.log(message); diff --git a/week-1/Homework/J-functions/exercise.js b/week-1/Homework/J-functions/exercise.js index 0ae5850e..d362595f 100644 --- a/week-1/Homework/J-functions/exercise.js +++ b/week-1/Homework/J-functions/exercise.js @@ -1,5 +1,5 @@ function halve(number) { - // complete the function here + return number/2 } var result = halve(12); diff --git a/week-1/Homework/J-functions/exercise2.js b/week-1/Homework/J-functions/exercise2.js index 82ef5e78..9b1665f5 100644 --- a/week-1/Homework/J-functions/exercise2.js +++ b/week-1/Homework/J-functions/exercise2.js @@ -1,5 +1,5 @@ function triple(number) { - // complete function here + return number*3 } var result = triple(12); diff --git a/week-1/Homework/K-functions-parameters/exercise.js b/week-1/Homework/K-functions-parameters/exercise.js index 8d5db5e6..d3402f75 100644 --- a/week-1/Homework/K-functions-parameters/exercise.js +++ b/week-1/Homework/K-functions-parameters/exercise.js @@ -1,9 +1,14 @@ -// Complete the function so that it takes input parameters -function multiply() { - // Calculate the result of the function and return it -} +// // Complete the function so that it takes input parameters +// function multiply(x,y) { +// return x*y +// } -// Assign the result of calling the function the variable `result` -var result = multiply(3, 4); +// // Assign the result of calling the function the variable `result` +// var result = multiply(3, 4); + +// console.log(result); + +const arrowMultiply = (x, y) => x*y; + +console.log(arrowMultiply(3,4)); -console.log(result); diff --git a/week-1/Homework/K-functions-parameters/exercise2.js b/week-1/Homework/K-functions-parameters/exercise2.js index db7a8904..8b37879a 100644 --- a/week-1/Homework/K-functions-parameters/exercise2.js +++ b/week-1/Homework/K-functions-parameters/exercise2.js @@ -1,4 +1,6 @@ -// Declare your function first +function divide(x,y) { + return x/y +} var result = divide(3, 4); diff --git a/week-1/Homework/K-functions-parameters/exercise3.js b/week-1/Homework/K-functions-parameters/exercise3.js index 537e9f4e..fa74fdf9 100644 --- a/week-1/Homework/K-functions-parameters/exercise3.js +++ b/week-1/Homework/K-functions-parameters/exercise3.js @@ -1,5 +1,6 @@ -// Write your function here - +function createGreeting(name) { + return `Hello ${name}, good night! I need to sleep.` +} var greeting = createGreeting("Daniel"); console.log(greeting); diff --git a/week-1/Homework/K-functions-parameters/exercise4.js b/week-1/Homework/K-functions-parameters/exercise4.js index 7ab44589..635f2836 100644 --- a/week-1/Homework/K-functions-parameters/exercise4.js +++ b/week-1/Homework/K-functions-parameters/exercise4.js @@ -1,5 +1,9 @@ // Declare your function first +function sumNumber(x,y) { + return x+y; +} +let sum = sumNumber(13,124) // Call the function and assign to a variable `sum` console.log(sum); diff --git a/week-1/Homework/K-functions-parameters/exercise5.js b/week-1/Homework/K-functions-parameters/exercise5.js index 7c5bcd60..8d6d9a05 100644 --- a/week-1/Homework/K-functions-parameters/exercise5.js +++ b/week-1/Homework/K-functions-parameters/exercise5.js @@ -1,5 +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); +const greeting = createLongGreeting("Amanda", 33); console.log(greeting); diff --git a/week-1/Homework/L-functions-nested/exercise.js b/week-1/Homework/L-functions-nested/exercise.js index a5d37744..5d8b9112 100644 --- a/week-1/Homework/L-functions-nested/exercise.js +++ b/week-1/Homework/L-functions-nested/exercise.js @@ -1,5 +1,36 @@ -var mentor1 = "Daniel"; -var mentor2 = "Irina"; -var mentor3 = "Mimi"; -var mentor4 = "Rob"; -var mentor5 = "Yohannes"; +var mentor1 = "Lucia"; +var mentor2 = "Giorgio"; +var mentor3 = "Fred"; +var mentor4 = "Ananda"; +var mentor5 = "Ali"; + +function upperCase(mentor) { + return mentor.toUpperCase(); + +} + +// let mentorUpper = upperCase(mentor1); +// console.log(mentorUpper); + + +// function greeting(mentor){ +// let mentorUpper = upperCase(mentor); +// console.log(`HELLO ${mentorUpper}`); +// // return `HELLO ${mentorUpper}` +// } + +// best way"" + +function greeting(mentor){ + console.log(`HELLO ${upperCase(mentor)}`); +} + + +// let hello = greeting(mentor1) +// console.log(hello); + +greeting(mentor1); +greeting(mentor2); +greeting(mentor3); +greeting(mentor4); +greeting(mentor5); diff --git a/week-1/InClass/exercise-A.js b/week-1/InClass/exercise-A.js index e69de29b..8230012f 100644 --- a/week-1/InClass/exercise-A.js +++ b/week-1/InClass/exercise-A.js @@ -0,0 +1 @@ +console.log("Hello World!!!") \ No newline at end of file diff --git a/week-1/InClass/exercise-B.js b/week-1/InClass/exercise-B.js index e69de29b..11f900fc 100644 --- a/week-1/InClass/exercise-B.js +++ b/week-1/InClass/exercise-B.js @@ -0,0 +1,10 @@ +console.log("Hello, world!") +console.log("Halo, dunia!") +console.log("Ciao, mundo!") +console.log("Olá, mundo!") +console.log("Hola, mundo!") +console.log("Hallo Welt") +console.log("Zdravo svijete") +console.log("Dia duit Domhanda") +console.log("Hola món") +console.log("مرحبا بالعالم") \ No newline at end of file diff --git a/week-1/InClass/exercise-C.js b/week-1/InClass/exercise-C.js index e69de29b..9fe8a9f9 100644 --- a/week-1/InClass/exercise-C.js +++ b/week-1/InClass/exercise-C.js @@ -0,0 +1,5 @@ +let greeting = "great day" + +console.log(greeting); +console.log(greeting); +console.log(greeting); diff --git a/week-1/InClass/exercise-D.js b/week-1/InClass/exercise-D.js index e69de29b..325b0a36 100644 --- a/week-1/InClass/exercise-D.js +++ b/week-1/InClass/exercise-D.js @@ -0,0 +1,7 @@ +let colors = "blue, yellow"; +console.log(colors); + +let numQuatro = 4; + +console.log("The datatype of numQuatro is: " + typeof numQuatro); +console.log("The datatype of colors is: " + typeof colors); diff --git a/week-1/InClass/exercise-E.js b/week-1/InClass/exercise-E.js index e69de29b..ad56ad5f 100644 --- a/week-1/InClass/exercise-E.js +++ b/week-1/InClass/exercise-E.js @@ -0,0 +1,8 @@ +const nome = "Amanda!"; +const greetingStart = "Hi, my name is "; + +const greeting = greetingStart + nome; +console.log(greeting); + +const newGreeting = `${greetingStart}, ${nome} and I'm linda!` +console.log(newGreeting); diff --git a/week-1/InClass/exercise-F.js b/week-1/InClass/exercise-F.js index e69de29b..2635d108 100644 --- a/week-1/InClass/exercise-F.js +++ b/week-1/InClass/exercise-F.js @@ -0,0 +1,7 @@ +const numberOfStudents = 15; +const numberOfMentors = 1; +let totalNumber = numberOfStudents + numberOfMentors; + +console.log(`Number of students: ${numberOfStudents}`); +console.log(`Number of mentors: ${numberOfMentors}`); +console.log(`Total number of students and mentors: ${totalNumber}`); \ No newline at end of file diff --git a/week-1/InClass/exercise-G.js b/week-1/InClass/exercise-G.js index e69de29b..47f081e2 100644 --- a/week-1/InClass/exercise-G.js +++ b/week-1/InClass/exercise-G.js @@ -0,0 +1,9 @@ +const numberOfStudents = 15; +const numberOfMentors = 1; +let totalNumber = numberOfStudents + numberOfMentors; + +const percentageStudents = `Percentage students: ${Math.round((numberOfStudents/totalNumber)*100)}%`; +const percentageMentors = `Percentage mentors: ${Math.round((numberOfMentors/totalNumber)*100)}%`; + +console.log(percentageStudents); +console.log(percentageMentors); diff --git a/week-1/InClass/exercise-H.js b/week-1/InClass/exercise-H.js index e69de29b..16f5ce50 100644 --- a/week-1/InClass/exercise-H.js +++ b/week-1/InClass/exercise-H.js @@ -0,0 +1,13 @@ +function exerciseH(num1, num2) { + let string = "The correct"; + return `${string} sum of two numbers is: ${num1 + num2}`; +} +// I created a function that receive two number and do a operation. And I created a variavle inside my function who has a string. Then I concatanate the string and operation to return. + + +let result = exerciseH(5,10); +// To read my function's return, I had to store this value on ohter variable (result). Then, to see on console, I used console.log(result). + +console.log(result); + +// the diference between console.log and return is the console.log show the result without store this value on variable. But if I want use this result in another part of my code, I have to use "return". diff --git a/week-1/InClass/exercise-I.js b/week-1/InClass/exercise-I.js index e69de29b..5e2fc85d 100644 --- a/week-1/InClass/exercise-I.js +++ b/week-1/InClass/exercise-I.js @@ -0,0 +1,11 @@ +function calculateYear(name, age){ + let calculate = 2022 - age; + return `${name}, you were born in ${calculate}.`; +} + +// first option +let year = calculateYear("Maria", 33); +console.log(year); + +// second option +console.log(calculateYear("Joao", 40)); \ No newline at end of file diff --git a/week-1/InClass/index.html b/week-1/InClass/index.html new file mode 100644 index 00000000..49e4eed9 --- /dev/null +++ b/week-1/InClass/index.html @@ -0,0 +1,16 @@ + + +
+ + + +