From d3ff9020783d43240377e045203cf593d0585374 Mon Sep 17 00:00:00 2001 From: Amanda Maria Date: Tue, 16 Aug 2022 19:40:49 +0200 Subject: [PATCH 1/9] exercises inClass A-E --- week-1/InClass/exercise-A.js | 1 + week-1/InClass/exercise-B.js | 10 ++++++++++ week-1/InClass/exercise-C.js | 5 +++++ week-1/InClass/exercise-D.js | 7 +++++++ week-1/InClass/exercise-E.js | 8 ++++++++ week-1/InClass/index.html | 16 ++++++++++++++++ 6 files changed, 47 insertions(+) create mode 100644 week-1/InClass/index.html 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/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 @@ + + + + + + + Document + + +

First Javascript's class!

+ + + + \ No newline at end of file From 5e41a59e769fbcad7e3341216fe344370623a2fb Mon Sep 17 00:00:00 2001 From: Amanda Maria Date: Tue, 16 Aug 2022 21:04:28 +0200 Subject: [PATCH 2/9] add exercise F, H and I --- week-1/InClass/exercise-F.js | 7 +++++++ week-1/InClass/exercise-H.js | 13 +++++++++++++ week-1/InClass/exercise-I.js | 9 +++++++++ 3 files changed, 29 insertions(+) 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-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..426535d5 100644 --- a/week-1/InClass/exercise-I.js +++ b/week-1/InClass/exercise-I.js @@ -0,0 +1,9 @@ +function calculateYear(age){ + let calculate = 2022 - age; + console.log(calculate); + return `You were born in ${calculate}.`; +} + +let year = calculateYear(33); + +console.log(year); \ No newline at end of file From 874b9ef958f9dccd94995ca1acdb614cd4aa014f Mon Sep 17 00:00:00 2001 From: Amanda Maria Date: Tue, 16 Aug 2022 22:12:20 +0200 Subject: [PATCH 3/9] finish inClass exercises --- week-1/Homework/F-strings-methods/exercise.js | 5 ++++- week-1/Homework/F-strings-methods/exercise2.js | 10 ++++++++-- week-1/InClass/exercise-G.js | 9 +++++++++ week-1/InClass/exercise-I.js | 9 +++++---- 4 files changed, 26 insertions(+), 7 deletions(-) diff --git a/week-1/Homework/F-strings-methods/exercise.js b/week-1/Homework/F-strings-methods/exercise.js index 2cffa6a8..19f87160 100644 --- a/week-1/Homework/F-strings-methods/exercise.js +++ b/week-1/Homework/F-strings-methods/exercise.js @@ -1,3 +1,6 @@ // Start by creating a variable `message` +let message = 'Amanda' +console.log(message); -console.log(message); +let lengthMessage = message.length; +console.log(`My name is ${message} ant the length of my name is ${lengthMessage}.`); \ No newline at end of file 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/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-I.js b/week-1/InClass/exercise-I.js index 426535d5..dfc12d02 100644 --- a/week-1/InClass/exercise-I.js +++ b/week-1/InClass/exercise-I.js @@ -1,9 +1,10 @@ -function calculateYear(age){ +function calculateYear(name, age){ let calculate = 2022 - age; console.log(calculate); - return `You were born in ${calculate}.`; + return `${name}, you were born in ${calculate}.`; } -let year = calculateYear(33); +let year = calculateYear("Maria", 33); -console.log(year); \ No newline at end of file +console.log(year); +console.log(calculateYear("Joao", 40)); \ No newline at end of file From 62acd553c4a176379deaa71957d27abe9a73a772 Mon Sep 17 00:00:00 2001 From: Amanda Maria Date: Tue, 16 Aug 2022 22:52:50 +0200 Subject: [PATCH 4/9] finish HW --- week-1/Homework/J-functions/exercise.js | 2 +- week-1/Homework/J-functions/exercise2.js | 2 +- .../K-functions-parameters/exercise.js | 4 +-- .../K-functions-parameters/exercise2.js | 4 ++- .../K-functions-parameters/exercise3.js | 5 +-- .../K-functions-parameters/exercise4.js | 4 +++ .../K-functions-parameters/exercise5.js | 6 ++-- .../Homework/L-functions-nested/exercise.js | 34 ++++++++++++++++--- 8 files changed, 47 insertions(+), 14 deletions(-) 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..2335772e 100644 --- a/week-1/Homework/K-functions-parameters/exercise.js +++ b/week-1/Homework/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(x,y) { + return x*y } // Assign the result of calling the function the variable `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..96d7ef54 100644 --- a/week-1/Homework/L-functions-nested/exercise.js +++ b/week-1/Homework/L-functions-nested/exercise.js @@ -1,5 +1,29 @@ -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(name) { + return name.toUpperCase(); + +} + +// let mentorUpper = upperCase(mentor1); +// console.log(mentorUpper); + + +function greeting(mentor){ + let mentorUpper = upperCase(mentor); + console.log(`HELLO ${mentorUpper}`) + // return `HELLO ${mentorUpper}` +} + +// let hello = greeting(mentor1) +// console.log(hello); + +greeting(mentor1); +greeting(mentor2); +greeting(mentor3); +greeting(mentor4); +greeting(mentor5); From d7087fd672af75c55441c387eb40739fec5883e4 Mon Sep 17 00:00:00 2001 From: Amanda Maria Date: Tue, 16 Aug 2022 23:57:34 +0200 Subject: [PATCH 5/9] add 1 and 2 extra --- week-1/Extra/1-syntax-errors.js | 11 ++++++----- week-1/Extra/2-logic-error.js | 7 +++---- week-1/Homework/L-functions-nested/exercise.js | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) 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/Homework/L-functions-nested/exercise.js b/week-1/Homework/L-functions-nested/exercise.js index 96d7ef54..5dcb653c 100644 --- a/week-1/Homework/L-functions-nested/exercise.js +++ b/week-1/Homework/L-functions-nested/exercise.js @@ -15,7 +15,7 @@ function upperCase(name) { function greeting(mentor){ let mentorUpper = upperCase(mentor); - console.log(`HELLO ${mentorUpper}`) + console.log(`HELLO ${mentorUpper}`); // return `HELLO ${mentorUpper}` } From 2e0379a665eddab6fc0539638df5083ffd1cac22 Mon Sep 17 00:00:00 2001 From: Amanda Maria Date: Wed, 17 Aug 2022 12:05:14 +0200 Subject: [PATCH 6/9] add extra 3 - 6 --- week-1/Extra/3-function-output.js | 4 ++++ week-1/Extra/4-tax.js | 11 +++++++++-- week-1/Extra/5-currency-conversion.js | 8 ++++++-- week-1/Extra/6-piping.js | 22 ++++++++++++++-------- week-1/Extra/7-magic-8-ball.js | 3 +++ 5 files changed, 36 insertions(+), 12 deletions(-) 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 ===== From e50b2862d520cf93f0740c72d31ae09732d4b601 Mon Sep 17 00:00:00 2001 From: Amanda Maria Date: Sat, 20 Aug 2022 12:03:29 +0200 Subject: [PATCH 7/9] add function on wee1k-HW-F-string-1 --- week-1/Homework/F-strings-methods/exercise.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/week-1/Homework/F-strings-methods/exercise.js b/week-1/Homework/F-strings-methods/exercise.js index 19f87160..cb9f0b7b 100644 --- a/week-1/Homework/F-strings-methods/exercise.js +++ b/week-1/Homework/F-strings-methods/exercise.js @@ -1,6 +1,11 @@ // Start by creating a variable `message` -let message = 'Amanda' -console.log(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"); -let lengthMessage = message.length; -console.log(`My name is ${message} ant the length of my name is ${lengthMessage}.`); \ No newline at end of file From eccbb4b63f199426447d109bea217eeb6a382b1e Mon Sep 17 00:00:00 2001 From: Amanda Maria Date: Mon, 22 Aug 2022 09:56:17 +0200 Subject: [PATCH 8/9] updating --- .../K-functions-parameters/exercise.js | 19 ++++++++++++------- .../Homework/L-functions-nested/exercise.js | 17 ++++++++++++----- week-1/InClass/exercise-I.js | 5 +++-- 3 files changed, 27 insertions(+), 14 deletions(-) diff --git a/week-1/Homework/K-functions-parameters/exercise.js b/week-1/Homework/K-functions-parameters/exercise.js index 2335772e..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(x,y) { - return x*y -} +// // 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/L-functions-nested/exercise.js b/week-1/Homework/L-functions-nested/exercise.js index 5dcb653c..5d8b9112 100644 --- a/week-1/Homework/L-functions-nested/exercise.js +++ b/week-1/Homework/L-functions-nested/exercise.js @@ -4,8 +4,8 @@ var mentor3 = "Fred"; var mentor4 = "Ananda"; var mentor5 = "Ali"; -function upperCase(name) { - return name.toUpperCase(); +function upperCase(mentor) { + return mentor.toUpperCase(); } @@ -13,12 +13,19 @@ function upperCase(name) { // console.log(mentorUpper); +// function greeting(mentor){ +// let mentorUpper = upperCase(mentor); +// console.log(`HELLO ${mentorUpper}`); +// // return `HELLO ${mentorUpper}` +// } + +// best way"" + function greeting(mentor){ - let mentorUpper = upperCase(mentor); - console.log(`HELLO ${mentorUpper}`); - // return `HELLO ${mentorUpper}` + console.log(`HELLO ${upperCase(mentor)}`); } + // let hello = greeting(mentor1) // console.log(hello); diff --git a/week-1/InClass/exercise-I.js b/week-1/InClass/exercise-I.js index dfc12d02..5e2fc85d 100644 --- a/week-1/InClass/exercise-I.js +++ b/week-1/InClass/exercise-I.js @@ -1,10 +1,11 @@ function calculateYear(name, age){ let calculate = 2022 - age; - console.log(calculate); 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 From 19abc342211ebb4b68362e56aa7a6022fac98936 Mon Sep 17 00:00:00 2001 From: Amanda Maria Date: Wed, 24 Aug 2022 13:04:49 +0200 Subject: [PATCH 9/9] add HW --- .../C-comparison-operators/exercise.js | 6 ++-- week-2/Homework/E-conditionals/exercise.js | 8 ++++- .../Homework/F-logical-operators/exercise.js | 8 ++--- .../Homework/F-logical-operators/exercise2.js | 32 ++++++++++++++++++- .../Homework/G-conditionals-2/exercise-1.js | 6 +++- .../Homework/G-conditionals-2/exercise-2.js | 6 +++- .../Homework/G-conditionals-2/exercise-3.js | 10 +++++- .../Homework/G-conditionals-2/exercise-4.js | 6 +++- week-2/Homework/H-array-literals/exercise.js | 8 +++-- .../Homework/I-array-properties/exercise.js | 6 +++- week-2/Homework/J-array-get-set/exercise.js | 5 +-- week-2/Homework/J-array-get-set/exercises2.js | 3 +- week-2/Homework/K-while-loop/exercise.js | 10 +++++- week-2/Homework/L-for-loop/exercise.js | 9 +++++- week-2/Homework/M-array-loop/exercise.js | 11 ++++++- week-2/InClass/exercise-B.js | 5 +-- week-2/InClass/exercise-C.js | 7 +++- week-2/InClass/exercise-D.js | 20 ++++++++++++ week-2/InClass/exercise-G.js | 5 +++ week-2/InClass/exercise-H.js | 10 ++++++ week-2/InClass/exercise-J.js | 10 ++++-- week-2/InClass/exercise-K.js | 15 +++++++++ week-2/InClass/test.html | 32 +++++++++++++++++++ 23 files changed, 210 insertions(+), 28 deletions(-) create mode 100644 week-2/InClass/test.html diff --git a/week-2/Homework/C-comparison-operators/exercise.js b/week-2/Homework/C-comparison-operators/exercise.js index 58aee1c5..5ce78210 100644 --- a/week-2/Homework/C-comparison-operators/exercise.js +++ b/week-2/Homework/C-comparison-operators/exercise.js @@ -7,14 +7,14 @@ var studentCount = 16; var mentorCount = 9; -var moreStudentsThanMentors; // finish this statement +var moreStudentsThanMentors = studentCount > mentorCount; // finish this statement var roomMaxCapacity = 25; -var enoughSpaceInRoom; // finish this statement +var enoughSpaceInRoom = (studentCount+mentorCount) <= roomMaxCapacity; // finish this statement var personA = "Daniel"; var personB = "Irina"; -var sameName; // finish this statement +var sameName = personA == personB; // finish this statement /* DO NOT EDIT BELOW THIS LINE diff --git a/week-2/Homework/E-conditionals/exercise.js b/week-2/Homework/E-conditionals/exercise.js index acbaaa8e..5a6eaed1 100644 --- a/week-2/Homework/E-conditionals/exercise.js +++ b/week-2/Homework/E-conditionals/exercise.js @@ -6,9 +6,15 @@ If Daniel is a student, print out "Hi, I'm Daniel, I'm a student." */ -var name = "Daniel"; +var nome = "Daniel"; var danielsRole = "mentor"; +if(nome === danielsRole) { + console.log("Hi, I'm Daniel, I'm a mentor.") +} else { + console.log("Hi, I'm Daniel, I'm a student.") +} + /* EXPECTED RESULT --------------- diff --git a/week-2/Homework/F-logical-operators/exercise.js b/week-2/Homework/F-logical-operators/exercise.js index a8f2945b..5b5ba773 100644 --- a/week-2/Homework/F-logical-operators/exercise.js +++ b/week-2/Homework/F-logical-operators/exercise.js @@ -11,14 +11,14 @@ var cssLevel = 4; // Finish the statement to check whether HTML, CSS knowledge are above 5 // (hint: use the comparison operator from before) -var htmlLevelAbove5; -var cssLevelAbove5; +var htmlLevelAbove5 = htmlLevel > 5; +var cssLevelAbove5 = cssLevel > 5; // Finish the next two statement // Use the previous variables and logical operators // Do not "hardcode" the answers -var cssAndHtmlAbove5; -var cssOrHtmlAbove5; +var cssAndHtmlAbove5 = (htmlLevel && cssLevel) > 5; +var cssOrHtmlAbove5 = (htmlLevel || cssLevel) > 5; /* DO NOT EDIT BELOW THIS LINE diff --git a/week-2/Homework/F-logical-operators/exercise2.js b/week-2/Homework/F-logical-operators/exercise2.js index fcc99247..51c82161 100644 --- a/week-2/Homework/F-logical-operators/exercise2.js +++ b/week-2/Homework/F-logical-operators/exercise2.js @@ -5,7 +5,37 @@ Update the code so that you get the expected result. */ -function isNegative() {} +function isNegative(number) { + if(number < 0){ + return true + } else { + return false + } +} + +function isBetween5and10(number) { + if (5 < number <= 10) { + return true + } else { + return false + } +} + +function isShortName(name){ + if ((name.length) < 7){ + return true + } else { + return false + } +} + +function startsWithD(name){ + if (name[0] === "D"){ + return true + } else { + return false + } +} /* DO NOT EDIT BELOW THIS LINE diff --git a/week-2/Homework/G-conditionals-2/exercise-1.js b/week-2/Homework/G-conditionals-2/exercise-1.js index 54708ef6..da5a38f5 100644 --- a/week-2/Homework/G-conditionals-2/exercise-1.js +++ b/week-2/Homework/G-conditionals-2/exercise-1.js @@ -7,7 +7,11 @@ */ function negativeOrPositive(number) { - + if(number < 0) { + return "negative" + } else { + return "positive" + } } /* diff --git a/week-2/Homework/G-conditionals-2/exercise-2.js b/week-2/Homework/G-conditionals-2/exercise-2.js index 313f3fb2..633b5396 100644 --- a/week-2/Homework/G-conditionals-2/exercise-2.js +++ b/week-2/Homework/G-conditionals-2/exercise-2.js @@ -8,7 +8,11 @@ */ function studentPassed(grade) { - + if (grade < 50){ + return "failed" + } else { + return "passed" + } } /* diff --git a/week-2/Homework/G-conditionals-2/exercise-3.js b/week-2/Homework/G-conditionals-2/exercise-3.js index a79cf30e..9e6f6f9a 100644 --- a/week-2/Homework/G-conditionals-2/exercise-3.js +++ b/week-2/Homework/G-conditionals-2/exercise-3.js @@ -9,7 +9,15 @@ */ function calculateGrade(mark) { - + if (mark >= 80) { + return "A" + } else if( 60 < mark && mark < 80) { + return "B" + } else if (50 <= mark && mark <= 60) { + return "C" + } else { + return "F" + } } /* diff --git a/week-2/Homework/G-conditionals-2/exercise-4.js b/week-2/Homework/G-conditionals-2/exercise-4.js index bd5bb1ef..8856ccf1 100644 --- a/week-2/Homework/G-conditionals-2/exercise-4.js +++ b/week-2/Homework/G-conditionals-2/exercise-4.js @@ -9,7 +9,11 @@ */ function containsCode(sentence) { - + if (sentence.includes("code")) { + return true + } else { + return false + } } /* diff --git a/week-2/Homework/H-array-literals/exercise.js b/week-2/Homework/H-array-literals/exercise.js index d6dc556a..86a2e0ee 100644 --- a/week-2/Homework/H-array-literals/exercise.js +++ b/week-2/Homework/H-array-literals/exercise.js @@ -4,8 +4,12 @@ Declare some variables assigned to arrays of values */ -var numbers = []; // add numbers from 1 to 10 into this array -var mentors; // Create an array with the names of the mentors: Daniel, Irina and Rares +var numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; // add numbers from 1 to 10 into this array +var mentors = ["Daniel", "Irina", "Rares"]; // Create an array with the names of the mentors: Daniel, Irina and Rares + + + + /* DO NOT EDIT BELOW THIS LINE diff --git a/week-2/Homework/I-array-properties/exercise.js b/week-2/Homework/I-array-properties/exercise.js index f9aec89f..1a202661 100644 --- a/week-2/Homework/I-array-properties/exercise.js +++ b/week-2/Homework/I-array-properties/exercise.js @@ -6,7 +6,11 @@ */ function isEmpty(arr) { - return; // complete this statement + if ((arr.length) === 0) { + return true; // complete this statement + } else { + return false; + } } /* diff --git a/week-2/Homework/J-array-get-set/exercise.js b/week-2/Homework/J-array-get-set/exercise.js index 3b95694e..016c9ae7 100644 --- a/week-2/Homework/J-array-get-set/exercise.js +++ b/week-2/Homework/J-array-get-set/exercise.js @@ -5,11 +5,12 @@ */ function first(arr) { - return; // complete this statement + return arr[0]; // complete this statement } function last(arr) { - return; // complete this statement + + return arr[arr.length -1]; // complete this statement } /* diff --git a/week-2/Homework/J-array-get-set/exercises2.js b/week-2/Homework/J-array-get-set/exercises2.js index 97f126f3..f365624f 100644 --- a/week-2/Homework/J-array-get-set/exercises2.js +++ b/week-2/Homework/J-array-get-set/exercises2.js @@ -7,7 +7,8 @@ */ var numbers = [1, 2, 3]; // Don't change this array literal declaration - + numbers.push(4); + numbers[0] = 1; /* DO NOT EDIT BELOW THIS LINE --------------------------- */ diff --git a/week-2/Homework/K-while-loop/exercise.js b/week-2/Homework/K-while-loop/exercise.js index c5662fe0..7afe9bac 100644 --- a/week-2/Homework/K-while-loop/exercise.js +++ b/week-2/Homework/K-while-loop/exercise.js @@ -9,7 +9,15 @@ let n = 10; function sumTillNum(num){ - //your code here + let soma = 0 + + while(num >= 0){ + console.log(num) + soma += num + num-- + } + + return soma } console.log("Sum from 0 to " + n + " is: " + sumTillNum(n)); diff --git a/week-2/Homework/L-for-loop/exercise.js b/week-2/Homework/L-for-loop/exercise.js index 151a60da..4c178c7a 100644 --- a/week-2/Homework/L-for-loop/exercise.js +++ b/week-2/Homework/L-for-loop/exercise.js @@ -9,7 +9,14 @@ let n = 10; function sumTillNum(num){ - //your code here + let soma = 0; + for (let i = 1; i <= num; i++) { + soma += i + console.log(i) + + } + + return soma } console.log("Sum from 0 to " + n + " is: " + sumTillNum(n)); diff --git a/week-2/Homework/M-array-loop/exercise.js b/week-2/Homework/M-array-loop/exercise.js index b79956a5..4145f818 100644 --- a/week-2/Homework/M-array-loop/exercise.js +++ b/week-2/Homework/M-array-loop/exercise.js @@ -12,4 +12,13 @@ const daysOfWeek = [ "Friday", "Saturday", "Sunday", -]; \ No newline at end of file +]; + +// a = daysOfWeek.filter(e => e[0] == 'T') +// console.log(a) + +for (let i = 0; i < daysOfWeek.length; i++) { + if (daysOfWeek[i][0] == 'T'){ + console.log(daysOfWeek[i]) + } +} \ No newline at end of file diff --git a/week-2/InClass/exercise-B.js b/week-2/InClass/exercise-B.js index 30864992..86f009bf 100644 --- a/week-2/InClass/exercise-B.js +++ b/week-2/InClass/exercise-B.js @@ -1,9 +1,10 @@ function boolChecker(bool) { - if (typeof bool === ) { + if (typeof bool === "boolean") { return "You've given me a bool, thanks!"; } return "No bool, not cool."; } -boolChecker(true); \ No newline at end of file +boolChecker(true); +console.log(boolChecker(false)); diff --git a/week-2/InClass/exercise-C.js b/week-2/InClass/exercise-C.js index ee280d79..f5398b15 100644 --- a/week-2/InClass/exercise-C.js +++ b/week-2/InClass/exercise-C.js @@ -8,4 +8,9 @@ function numberChecker(num) { } else { return `${num} isn't even a number :(`; } -} \ No newline at end of file +} + +//1. if: test conditional if num > 20 and return string talkin about; +//2. else if: testing other conditional if num is equal in value and type; +// testing if number is menor than 20 +// test if number is number \ No newline at end of file diff --git a/week-2/InClass/exercise-D.js b/week-2/InClass/exercise-D.js index e69de29b..68e506d0 100644 --- a/week-2/InClass/exercise-D.js +++ b/week-2/InClass/exercise-D.js @@ -0,0 +1,20 @@ + + +// let inputUser = promp("say something: ") + +function iAmHappy(status) { + if (status == "happy") { + return "Good job, you're doing great!" + } else if (status == "sad") { + return "Every cloud has a silver lining" + } else if (typeof status == "number") { + return "Beep beep boop" + } else { + return "I'm sorry, I'm still learning about feelings!" + } +} + +console.log(iAmHappy("happy")); +console.log(iAmHappy("amanda")); +console.log(iAmHappy(4)); +console.log(iAmHappy("sad")); \ No newline at end of file diff --git a/week-2/InClass/exercise-G.js b/week-2/InClass/exercise-G.js index efbb01e2..695ed5b2 100644 --- a/week-2/InClass/exercise-G.js +++ b/week-2/InClass/exercise-G.js @@ -1,4 +1,9 @@ var apolloCountdownMessage = "all engine running... LIFT-OFF!"; var countdown = 8; +while (countdown >= 0){ + console.log(countdown); + countdown-- +} + console.log(apolloCountdownMessage); \ No newline at end of file diff --git a/week-2/InClass/exercise-H.js b/week-2/InClass/exercise-H.js index 1a1bef7b..99ab5de0 100644 --- a/week-2/InClass/exercise-H.js +++ b/week-2/InClass/exercise-H.js @@ -4,4 +4,14 @@ function exponential(number) { function isEven(number) { return number % 2 === 0; +} + +for(let number = 5; 5 < number < 21; number++) { + function exponential(number) { + return number * number; + } + + function isEven(number) { + return number % 2 === 0; + } } \ No newline at end of file diff --git a/week-2/InClass/exercise-J.js b/week-2/InClass/exercise-J.js index 1c14afe9..f82cfd90 100644 --- a/week-2/InClass/exercise-J.js +++ b/week-2/InClass/exercise-J.js @@ -1,6 +1,10 @@ -function secondMatchesAmy(array) { - if ( ) { +let arrayNames = ["Amanda","Amy","Maria","Jon",] + +function secondMatchesAmy(arrayNames) { + if (arrayNames[1]== "Amy") { return "Second index matched!"; } return "Second index not matched"; -} \ No newline at end of file +} + +console.log(secondMatchesAmy(arrayNames)); \ No newline at end of file diff --git a/week-2/InClass/exercise-K.js b/week-2/InClass/exercise-K.js index e69de29b..858ad577 100644 --- a/week-2/InClass/exercise-K.js +++ b/week-2/InClass/exercise-K.js @@ -0,0 +1,15 @@ +const students = [ + "Amanda", + "Nuno", + "Daniele", + "Zakaria", + "Nimra", + "Hanna", + "Yun", + ]; + + for (let i = 0; i < students.length; i++) { + const dayMessage = "Hi " + students[i]; + // const indexMessage = "index is: " + i; + console.log(dayMessage); + } \ No newline at end of file diff --git a/week-2/InClass/test.html b/week-2/InClass/test.html new file mode 100644 index 00000000..61589c73 --- /dev/null +++ b/week-2/InClass/test.html @@ -0,0 +1,32 @@ + + + + + + + Document + + + + + \ No newline at end of file