diff --git a/week-1/.vscode/settings.json b/week-1/.vscode/settings.json new file mode 100644 index 00000000..6f3a2913 --- /dev/null +++ b/week-1/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "liveServer.settings.port": 5501 +} \ No newline at end of file diff --git a/week-1/Homework/F-strings-methods/exercise.js b/week-1/Homework/F-strings-methods/exercise.js index 2cffa6a8..3c48c640 100644 --- a/week-1/Homework/F-strings-methods/exercise.js +++ b/week-1/Homework/F-strings-methods/exercise.js @@ -1,3 +1,9 @@ // Start by creating a variable `message` -console.log(message); +const nameUser = "Cristiane"; +const nameLength = nameUser.length; + +console.log(`My name is ${nameUser} and my name have ${nameLength +} characters long.`); + +//Prints: My name is Cristiane and my name have 12 characters long. diff --git a/week-1/Homework/F-strings-methods/exercise2.js b/week-1/Homework/F-strings-methods/exercise2.js index b4b46943..d8e21078 100644 --- a/week-1/Homework/F-strings-methods/exercise2.js +++ b/week-1/Homework/F-strings-methods/exercise2.js @@ -1,3 +1,10 @@ -const name = " Daniel "; +const nameUser = " Cristiane "; +const nameLength = nameUser.length; -console.log(message); + +const message = `My name is ${nameUser.trim()} and my name have ${nameLength +} characters long.`; + +console.log(message); + +// prints: My name is Cristiane and my name have 12 characters long. diff --git a/week-1/Homework/J-functions/exercise.js b/week-1/Homework/J-functions/exercise.js index 0ae5850e..defd07a4 100644 --- a/week-1/Homework/J-functions/exercise.js +++ b/week-1/Homework/J-functions/exercise.js @@ -1,7 +1,16 @@ function halve(number) { // complete the function here + return number / 2; } -var result = halve(12); +let result = halve(12); // prints 6 + +let result = halve(17); // print 8.5 + +let result = halve(1287); //prints 643.5 + +let result = halve(20); //prints + +console.log(result); + -console.log(result); diff --git a/week-1/Homework/J-functions/exercise2.js b/week-1/Homework/J-functions/exercise2.js index 82ef5e78..0333c8df 100644 --- a/week-1/Homework/J-functions/exercise2.js +++ b/week-1/Homework/J-functions/exercise2.js @@ -1,7 +1,14 @@ function triple(number) { // complete function here + return number * 3; } -var result = triple(12); +let result = triple(12); // prints 6 -console.log(result); +let result = triple(22); // prints 66 + +let result = triple(222); // prints 666 + +let result = triple(2222); // prints 6666 + +console.log(result); diff --git a/week-1/Homework/K-functions-parameters/exercise.js b/week-1/Homework/K-functions-parameters/exercise.js index 8d5db5e6..c35269da 100644 --- a/week-1/Homework/K-functions-parameters/exercise.js +++ b/week-1/Homework/K-functions-parameters/exercise.js @@ -1,9 +1,10 @@ // Complete the function so that it takes input parameters -function multiply() { +function multiply(num1, num2) { // Calculate the result of the function and return it + return num1 * num2; } // Assign the result of calling the function the variable `result` -var result = multiply(3, 4); +const result = multiply(3, 4); -console.log(result); +console.log(result); // prints 12 diff --git a/week-1/Homework/K-functions-parameters/exercise2.js b/week-1/Homework/K-functions-parameters/exercise2.js index db7a8904..36f4e306 100644 --- a/week-1/Homework/K-functions-parameters/exercise2.js +++ b/week-1/Homework/K-functions-parameters/exercise2.js @@ -1,5 +1,8 @@ // Declare your function first +function divide(num1, num2){ + return num1 / num2; +} -var result = divide(3, 4); +const result = divide(3, 4); -console.log(result); +console.log(result); // prints 0.75 diff --git a/week-1/Homework/K-functions-parameters/exercise3.js b/week-1/Homework/K-functions-parameters/exercise3.js index 537e9f4e..1928193b 100644 --- a/week-1/Homework/K-functions-parameters/exercise3.js +++ b/week-1/Homework/K-functions-parameters/exercise3.js @@ -1,5 +1,8 @@ // Write your function here +function createGreeting(name){ + return `Hello, my name is ${name}.`; +} -var greeting = createGreeting("Daniel"); +const greeting = createGreeting("Cristiane"); -console.log(greeting); +console.log(greeting); // Prints: Hello, my name is Cristiane. diff --git a/week-1/Homework/K-functions-parameters/exercise4.js b/week-1/Homework/K-functions-parameters/exercise4.js index 7ab44589..5f7630aa 100644 --- a/week-1/Homework/K-functions-parameters/exercise4.js +++ b/week-1/Homework/K-functions-parameters/exercise4.js @@ -1,5 +1,10 @@ // Declare your function first +function numbers(num1, num2){ + return num1 + num2; +} // Call the function and assign to a variable `sum` -console.log(sum); +const sum = numbers(13, 124); + +console.log(sum); // prints 137 diff --git a/week-1/Homework/K-functions-parameters/exercise5.js b/week-1/Homework/K-functions-parameters/exercise5.js index 7c5bcd60..9457d4ca 100644 --- a/week-1/Homework/K-functions-parameters/exercise5.js +++ b/week-1/Homework/K-functions-parameters/exercise5.js @@ -1,5 +1,8 @@ // 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); -console.log(greeting); +console.log(greeting); // prints: Hello, my name is Daniel and I'm 30 years old. diff --git a/week-1/Homework/L-functions-nested/exercise.js b/week-1/Homework/L-functions-nested/exercise.js index a5d37744..1ff0bb4c 100644 --- a/week-1/Homework/L-functions-nested/exercise.js +++ b/week-1/Homework/L-functions-nested/exercise.js @@ -1,5 +1,30 @@ -var mentor1 = "Daniel"; -var mentor2 = "Irina"; -var mentor3 = "Mimi"; -var mentor4 = "Rob"; -var mentor5 = "Yohannes"; +const mentor1 = "Daniel"; +const mentor2 = "Irina"; +const mentor3 = "Mimi"; +const mentor4 = "Rob"; +const mentor5 = "Yohannes"; + +function mentors(mentor){ + const nameInUpperCase = mentor.toUpperCase(); + return nameInUpperCase; +} +// segunda parte del ejercicio: + +function shoutingOutLoud (mentor){ + return `HELLO ${mentor.toUpperCase()}` +} + +console.log(shoutingOutLoud(mentor1)); +console.log(shoutingOutLoud(mentor2)); +console.log(shoutingOutLoud(mentor3)); +console.log(shoutingOutLoud(mentor4)); +console.log(shoutingOutLoud(mentor5)); + +/* prints: +HELLO DANIEL +HELLO IRINA +HELLO MIMI +HELLO ROB +HELLO YOHANNES +*/ + diff --git a/week-1/InClass/ejercicio-sabado.js b/week-1/InClass/ejercicio-sabado.js new file mode 100644 index 00000000..e3923dbc --- /dev/null +++ b/week-1/InClass/ejercicio-sabado.js @@ -0,0 +1,27 @@ +function resumen(texto) { + return texto.substring(0, 9); +} + +const resultadoTexto = resumen("Hola este es un texto de prueba"); + +console.log(resultadoTexto.slice(0,9)); // Recibimos el resultado: Hola este + +/* +console.log("hola esta es una prueba del slice".slice(1,3)); // printa ol +console.log("hola esta es una prueba del slice".substring(1,3)); // printa ol -- igual al .slice +console.log("hola esta es una prueba del slice".slice(0,9)); // printa hola esta +console.log("hola esta es una prueba del slice".substring(0,9)); // printa hol a esta --igual al .slice + +*/ + +// Second exercise + +function firstCapitalize(text){ + const firstChar = text.charAt(0); + const firstCharCapitalize = firstChar.toUpperCase(); + return firstCharCapitalize + text.slice(1); +} + +const resultadoEjercicioDos = firstCapitalize("mi mensagen bien escrito"); + +console.log(resultadoEjercicioDos); \ No newline at end of file diff --git a/week-1/InClass/exercise-A.js b/week-1/InClass/exercise-A.js index e69de29b..019c0f4b 100644 --- a/week-1/InClass/exercise-A.js +++ b/week-1/InClass/exercise-A.js @@ -0,0 +1 @@ +console.log("Hello World!"); diff --git a/week-1/InClass/exercise-B.js b/week-1/InClass/exercise-B.js index e69de29b..13fb5234 100644 --- a/week-1/InClass/exercise-B.js +++ b/week-1/InClass/exercise-B.js @@ -0,0 +1,11 @@ +console.log("Hello World!"); +console.log("Olá mundo! // Brasil"); +console.log("Holá mundo! // España"); +console.log("Hei Verden // Noruego"); +console.log("Ciao World // Italia"); +console.log("Hallo Weld // Alemania"); +console.log("Hej världen // Sueco"); +console.log("Witaj świecie // Polaco"); +console.log("नमस्ते दुनिया // Hindi"); +console.log("Aloha Honua // Hawaiano") +console.log("Helló Világ // Hungaro"); diff --git a/week-1/InClass/exercise-C.js b/week-1/InClass/exercise-C.js index e69de29b..4cb831e6 100644 --- a/week-1/InClass/exercise-C.js +++ b/week-1/InClass/exercise-C.js @@ -0,0 +1,5 @@ +let greeting = "Hello World" + +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..94842728 100644 --- a/week-1/InClass/exercise-D.js +++ b/week-1/InClass/exercise-D.js @@ -0,0 +1,5 @@ +const colors = "blue, yellow"; + +console.log(typeof colors); + +console.log(colors); diff --git a/week-1/InClass/exercise-E.js b/week-1/InClass/exercise-E.js index e69de29b..225db0f6 100644 --- a/week-1/InClass/exercise-E.js +++ b/week-1/InClass/exercise-E.js @@ -0,0 +1,9 @@ +const greetingStart = "Hello, my name is "; +const nameUser = "Cristiane"; + +const greeting = greetingStart + nameUser; + + +console.log(greeting); + +console.log(greetingStart + nameUser); diff --git a/week-1/InClass/exercise-F.js b/week-1/InClass/exercise-F.js index e69de29b..5602cf61 100644 --- a/week-1/InClass/exercise-F.js +++ b/week-1/InClass/exercise-F.js @@ -0,0 +1,14 @@ +const numberOfStudents = 15; + +const numberofMentors = 8; + +const totalNumberOfClass = numberOfStudents + numberofMentors; + + +console.log(`Number of students: ${numberOfStudents}.`); + +console.log(`Number of mentors: ${numberofMentors}.`); + +console.log(`Total number of students and mentors: ${numberOfStudents + numberofMentors}.`); + +console.log('Total number of students and mentors:' + totalNumberOfClass ); \ No newline at end of file diff --git a/week-1/InClass/exercise-G.js b/week-1/InClass/exercise-G.js index e69de29b..91be474c 100644 --- a/week-1/InClass/exercise-G.js +++ b/week-1/InClass/exercise-G.js @@ -0,0 +1,13 @@ +const numberOfStudents = 15; + +const numberofMentors = 8; + +const totalNumberOfClass = numberOfStudents + numberofMentors; + +const percentageOfStudents = (100 * numberOfStudents) /totalNumberOfClass; + +const percentageOfMentors = (100 * numberofMentors) / totalNumberOfClass; + +console.log("Percentage students: " + Math.round(percentageOfStudents) + "%"); + +console.log("Percentage mentors: " + Math.round(percentageOfMentors) + "%"); diff --git a/week-1/InClass/exercise-H.js b/week-1/InClass/exercise-H.js index e69de29b..8c63cd4d 100644 --- a/week-1/InClass/exercise-H.js +++ b/week-1/InClass/exercise-H.js @@ -0,0 +1,22 @@ +function numbers (num1, num2){ + return num1 + num2; +} + +// The function it get the num1 and add numb2 + +const randomNumbers = numbers(5, 10) + +console.log(randomNumbers) + +/* What's the difference between a return and console.log? + + - A return statement ends the execution of a function, and returns control to the calling function. + Execution resumes in the calling function at the point immediately following the call. + A return statement can return a value to the calling function. + - console.log - prints the result on the screen + + When would you choose to use functions over the way we have been scripting so far? + + -We choose the functions ( is a kind of block of codes)when we need to execute it repetitive times, so we do not need to write every single line and let the function do the job after giving it the correcter parameters. + +*/ \ No newline at end of file diff --git a/week-1/InClass/exercise-I.js b/week-1/InClass/exercise-I.js index e69de29b..2e5d2668 100644 --- a/week-1/InClass/exercise-I.js +++ b/week-1/InClass/exercise-I.js @@ -0,0 +1,18 @@ +const year = 2022 // global variable + +function returnBornDate(yearsOld){ + return year - yearsOld; +} + +console.log(returnBornDate(34)); // prints 1988 + +//Second part of the excercise: + +function greetings(name, age){ + return ` Hello, my name is ${name} and I've born in ${returnBornDate(age)}.` +// }; +} + +console.log(greetings("Cristiane", 34)); // prints: Hello, my name is Cristiane and I've born in 1988. + + diff --git a/week-1/InClass/practica.js b/week-1/InClass/practica.js new file mode 100644 index 00000000..2bf090c7 --- /dev/null +++ b/week-1/InClass/practica.js @@ -0,0 +1,5 @@ +const max = 19; +const min =1; + +console.log(Math.floor(Math.random() * (max - min + 1) +1)); + diff --git a/week-2/Homework/C-comparison-operators/exercise.js b/week-2/Homework/C-comparison-operators/exercise.js index 58aee1c5..801b3158 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 = roomMaxCapacity >= (studentCount + mentorCount);// 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..0a285dd3 100644 --- a/week-2/Homework/E-conditionals/exercise.js +++ b/week-2/Homework/E-conditionals/exercise.js @@ -9,7 +9,16 @@ var name = "Daniel"; var danielsRole = "mentor"; +if(danielsRole === "mentor"){ + console.log("Hi, I'm " + name + ", I'm a mentor.") +} else { + console.log("Hi, I'm " + name + ", I'm a student.") +} + /* + +Prints: + EXPECTED RESULT --------------- Hi, I'm Daniel, I'm a mentor. diff --git a/week-2/Homework/F-logical-operators/exercise.js b/week-2/Homework/F-logical-operators/exercise.js index a8f2945b..90469cac 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 = htmlLevelAbove5 && cssLevelAbove5; +var cssOrHtmlAbove5 = htmlLevelAbove5 || cssLevelAbove5; /* 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..e65bb652 100644 --- a/week-2/Homework/F-logical-operators/exercise2.js +++ b/week-2/Homework/F-logical-operators/exercise2.js @@ -5,7 +5,27 @@ Update the code so that you get the expected result. */ -function isNegative() {} +function isNegative(number) { + return number < 0 +} +function isBetween5and10(number){ + return number >= 5 && number <=10 +} + +//nombre corto es hasta 6 caracteres? + +function isShortName(person){ + let nameLength = person.length; + return nameLength <= 6 +} + +function startsWithD(personName){ + let firstCharacter = personName[0] + return firstCharacter === "D" + +} + + /* 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..f19357b4 100644 --- a/week-2/Homework/G-conditionals-2/exercise-1.js +++ b/week-2/Homework/G-conditionals-2/exercise-1.js @@ -7,7 +7,9 @@ */ function negativeOrPositive(number) { - + if (number >= 0){ + return "positive" + } return "negative" } /* diff --git a/week-2/Homework/G-conditionals-2/exercise-2.js b/week-2/Homework/G-conditionals-2/exercise-2.js index 313f3fb2..1d3f59ca 100644 --- a/week-2/Homework/G-conditionals-2/exercise-2.js +++ b/week-2/Homework/G-conditionals-2/exercise-2.js @@ -9,6 +9,12 @@ function studentPassed(grade) { + if (grade < 50){ + return "failed" + } else {(grade > 50 ) + 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..574ba082 100644 --- a/week-2/Homework/G-conditionals-2/exercise-3.js +++ b/week-2/Homework/G-conditionals-2/exercise-3.js @@ -9,7 +9,13 @@ */ function calculateGrade(mark) { - +if (mark < 50 ){ + return "F" +}else if ( mark <= 50 && mark <= 60){ + return "C" +} else if (mark > 60 && mark < 80){ + return "B" +} return "A" } /* @@ -18,7 +24,7 @@ DO NOT EDIT BELOW THIS LINE var grade1 = 49; var grade2 = 90; var grade3 = 70; -var grade4 = 55; +var grade4 = 50; console.log("'" + grade1 + "': " + calculateGrade(grade1)); console.log("'" + grade2 + "': " + calculateGrade(grade2)); diff --git a/week-2/Homework/G-conditionals-2/exercise-4.js b/week-2/Homework/G-conditionals-2/exercise-4.js index bd5bb1ef..d6535ce1 100644 --- a/week-2/Homework/G-conditionals-2/exercise-4.js +++ b/week-2/Homework/G-conditionals-2/exercise-4.js @@ -6,11 +6,14 @@ - otherwise return false Hint: Google how to check if a string contains a word + + podemos utilizar o methodo includes() + */ function containsCode(sentence) { - -} + return sentence.includes('code') +} /* DO NOT EDIT BELOW THIS LINE diff --git a/week-2/Homework/H-array-literals/exercise.js b/week-2/Homework/H-array-literals/exercise.js index d6dc556a..63acfce9 100644 --- a/week-2/Homework/H-array-literals/exercise.js +++ b/week-2/Homework/H-array-literals/exercise.js @@ -4,8 +4,8 @@ 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 = [0,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 @@ -13,7 +13,11 @@ var mentors; // Create an array with the names of the mentors: Daniel, Irina and console.log(numbers); console.log(mentors); -/* + + +/* prints : + + EXPECTED RESULT --------------- [1,2,3,4,5,6,7,8,9,10] diff --git a/week-2/Homework/I-array-properties/exercise.js b/week-2/Homework/I-array-properties/exercise.js index f9aec89f..a2280a89 100644 --- a/week-2/Homework/I-array-properties/exercise.js +++ b/week-2/Homework/I-array-properties/exercise.js @@ -6,7 +6,7 @@ */ function isEmpty(arr) { - return; // complete this statement + return arr.length === 0; // complete this statement } /* diff --git a/week-2/Homework/J-array-get-set/exercise.js b/week-2/Homework/J-array-get-set/exercise.js index 3b95694e..6f15d4c0 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 } /* @@ -22,7 +23,8 @@ console.log(first(numbers)); console.log(last(numbers)); console.log(last(names)); -/* +/* Prints: + EXPECTED RESULT --------------- 1 diff --git a/week-2/Homework/J-array-get-set/exercises2.js b/week-2/Homework/J-array-get-set/exercises2.js index 97f126f3..d200c532 100644 --- a/week-2/Homework/J-array-get-set/exercises2.js +++ b/week-2/Homework/J-array-get-set/exercises2.js @@ -8,6 +8,8 @@ var numbers = [1, 2, 3]; // Don't change this array literal declaration +numbers[3] = 4 + /* DO NOT EDIT BELOW THIS LINE --------------------------- */ @@ -16,5 +18,5 @@ console.log(numbers); /* EXPECTED RESULT --------------- - [1, 2, 3, 4] + [1, 2, 3, 4] */ diff --git a/week-2/Homework/K-while-loop/exercise.js b/week-2/Homework/K-while-loop/exercise.js index c5662fe0..e0792dd9 100644 --- a/week-2/Homework/K-while-loop/exercise.js +++ b/week-2/Homework/K-while-loop/exercise.js @@ -10,6 +10,16 @@ let n = 10; function sumTillNum(num){ //your code here + let counter = 0; + let result = 0; + while ( counter <=num){ + result += counter; + counter ++; + } + return result; } console.log("Sum from 0 to " + n + " is: " + sumTillNum(n)); + + +// Prints: Sum from 0 to 10 is: 55 \ No newline at end of file diff --git a/week-2/Homework/L-for-loop/exercise.js b/week-2/Homework/L-for-loop/exercise.js index 151a60da..3c5912e3 100644 --- a/week-2/Homework/L-for-loop/exercise.js +++ b/week-2/Homework/L-for-loop/exercise.js @@ -8,8 +8,32 @@ let n = 10; +/* + function sumTillNum(num){ //your code here + let suma = [] + for (let counter = 0; counter <= num; counter++){ + suma.push(counter) + } + return suma.toString().replace(/,/g,"+") } console.log("Sum from 0 to " + n + " is: " + sumTillNum(n)); + +// prints: Sum from 0 to 10 is: 0+1+2+3+4+5+6+7+8+9+10 + +*/ + +function sumTillNum(num){ + //your code here + let suma = 0; + for (let counter = 0; counter <= num; counter++){ + suma = suma + counter; // o suma += counter; + } + return suma +} + +console.log("Sum from 0 to " + n + " is: " + sumTillNum(n)); + +//prints: Sum from 0 to 10 is: 55 \ No newline at end of file diff --git a/week-2/Homework/M-array-loop/exercise.js b/week-2/Homework/M-array-loop/exercise.js index b79956a5..a8d7a2e5 100644 --- a/week-2/Homework/M-array-loop/exercise.js +++ b/week-2/Homework/M-array-loop/exercise.js @@ -4,6 +4,17 @@ */ +function getDaysStartingWithT(array){ + + for (let i=0; i < array.length; i++){ + const day = array[i]; + if (day.startsWith('T')){ + console.log(day) + } + } + +} + const daysOfWeek = [ "Monday", "Tuesday", @@ -12,4 +23,14 @@ const daysOfWeek = [ "Friday", "Saturday", "Sunday", -]; \ No newline at end of file +]; + +getDaysStartingWithT(daysOfWeek) + + /* prints: + + Tuesday +Thursday + + +*/ \ No newline at end of file diff --git a/week-2/InClass/exercise-A.js b/week-2/InClass/exercise-A.js index e69de29b..b8fcd605 100644 --- a/week-2/InClass/exercise-A.js +++ b/week-2/InClass/exercise-A.js @@ -0,0 +1,9 @@ +// on VS CODE TERMINAL ( NODE REPL) + +1 + 2 // prints 3; + +"hello" // prints 'hello' + +let favoriteColour = "purple" ; // prints undefined - it means it is not showed on screen + +console.log(favoriteColour) // prints purple - undefined diff --git a/week-2/InClass/exercise-B.js b/week-2/InClass/exercise-B.js index 30864992..88fc630a 100644 --- a/week-2/InClass/exercise-B.js +++ b/week-2/InClass/exercise-B.js @@ -1,9 +1,41 @@ 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 +console.log(boolChecker(true)); // prints : You've given me a bool, thanks! + +/* +Node REPL: + +1- In a node REPL, what is the typeof a true or false? + The type of true and false are both 'boolean' - primitive type + +1.1 - As a class, can you step through the function and explain what each line does? + + +LINE 1 <---- START: giving a name to a function (boolChecker )and adding parameter to the name function (bool) + +LINE 3 <---- IF the type of the parameter (bool) is exactly like a boolean ( primitive type that is both trye or false), + +LINE 4 <---- it will return the message: You've given me a bool, thanks! + +LINE 5 <----- IF the type of the parameter isnt a boolean ( can be number / string / objetc, etc), + +LINE 6 <----- it will return : No bool, not cool. + +LINE 7 <----- End of the funcion. + + +LINE 9 <----- We print to the console throught the command console.log, calling the funcion inside the parentheses. + inserting as an argument after the name of the funcion inside another parentheses, one of the results of a boolean to confirm if match or now in our funcion. + + As a result checked on Node REPL, it prints + +console.log(boolChecker(true)); // prints: You've given me a bool, thanks! + + +*/ diff --git a/week-2/InClass/exercise-C.js b/week-2/InClass/exercise-C.js index ee280d79..a519e147 100644 --- a/week-2/InClass/exercise-C.js +++ b/week-2/InClass/exercise-C.js @@ -8,4 +8,46 @@ function numberChecker(num) { } else { return `${num} isn't even a number :(`; } -} \ No newline at end of file +} + +console.log(numberChecker("name")) + + +/* +Can you explain what this function does line by line? + What happens when you pass in a string? + + LINE 1 <---- Start: giving a name to a function (numberChecker) and adding a parameter to this namefunction (num); + + LINE 2 <---- If the parameter (num) is greater than 20, + + LINE 3 <----- it will return the message: (num) is greater than 20; + + LINE 4 <----- Else if the parameter (num) is equal type and value than 20, + + LINE 5 <----- it will return the message: (num)is greater than 20; + + LINE 6 <----- Else if the parameter (num) is less than 20, + + LINE 7 <----- it will return the message: (num)is less than 20; + + LINE 8 <----- Else the parameter (num) isnot a number ( string, object, etc), + + LINE 9 <----- it will return the message: (num)is not even a number :'(; + + LINE 11 <----- End of the funcion. + + LINE 13 <----- We print to the console throught the command console.log, calling the funcion inside the parentheses. + inserting as an argument what we need to know it matches with one of the conditions of the function. + + As a result checked on Node REPL, it prints + + name isn't even a number :( + + + + + + +*/ + diff --git a/week-2/InClass/exercise-D.js b/week-2/InClass/exercise-D.js index e69de29b..69b8bad2 100644 --- a/week-2/InClass/exercise-D.js +++ b/week-2/InClass/exercise-D.js @@ -0,0 +1,13 @@ +function moodOfTheDay(mood){ + if (mood === "happy"){ + return "Good job, you're doing great!" + } else if (mood === "sad"){ + return "Every cloud has a silver lining" + } else if (typeof mood === "number"){ + return "Beep beep boop" + } else { + return "I'm sorry, I'm still learning about feelings!" + } +} + +console.log(moodOfTheDay(1980)); // it prints: Beep beep boo \ No newline at end of file diff --git a/week-2/InClass/exercise-E.js b/week-2/InClass/exercise-E.js index e69de29b..84390a25 100644 --- a/week-2/InClass/exercise-E.js +++ b/week-2/InClass/exercise-E.js @@ -0,0 +1,8 @@ +let num = 10 +num > 5 && num < 15; //true +num < 10 || num === 10; // true; +false || true; // true; +!true // false +let greaterThan5 = num > 5; // true; +!greaterThan5 /* ! implica lo contrario - falso; */ +!(num === 10); /* ! implica lo comtrario - falso; */ diff --git a/week-2/InClass/exercise-F.js b/week-2/InClass/exercise-F.js index e69de29b..8bdda7cd 100644 --- a/week-2/InClass/exercise-F.js +++ b/week-2/InClass/exercise-F.js @@ -0,0 +1,15 @@ + +function validName(username,type ) { + const firstLetter = username.charAt(0); + const userLenght = username.Lenght; + const isValidLength = userLenght >= 5 && userLenght <=10; + const isASuperType = type === "admin" || type ==="manager"; + + if ( isASuperType || ( firstLetter === firstLetter.toUpperCase() && isValidLength ) ){ + return "Username Valid" + } else { + return "Username invalid"; + } +} + +console.log(validName("Critiane", "admin")); //it prints: Username Valid \ No newline at end of file diff --git a/week-2/InClass/exercise-G.js b/week-2/InClass/exercise-G.js index efbb01e2..1f40dbef 100644 --- a/week-2/InClass/exercise-G.js +++ b/week-2/InClass/exercise-G.js @@ -1,4 +1,28 @@ -var apolloCountdownMessage = "all engine running... LIFT-OFF!"; -var countdown = 8; +const apolloCountdownMessage = "all engine running... LIFT-OFF!"; + + +let countdown = 8; + +while (countdown >= 0){ + console.log(countdown); + countdown-- ; +} + +console.log(apolloCountdownMessage); + + +/* Prints + +8 +7 +6 +5 +4 +3 +2 +1 +0 +all engine running... LIFT-OFF! + +*/ -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..4a55399f 100644 --- a/week-2/InClass/exercise-H.js +++ b/week-2/InClass/exercise-H.js @@ -1,7 +1,30 @@ + + function exponential(number) { - return number * number; + return number * number; // o number **2 } function isEven(number) { return number % 2 === 0; -} \ No newline at end of file +} + +for ( let number = 5; number < 20; number++ ) { // o 20 < number + if (isEven(number)){ + console.log(`The exponencial of ${number} is ${exponential(number)}`); + + + } +} + +/* +Prints + +The exponencial of 6 is 36 +The exponencial of 8 is 64 +The exponencial of 10 is 100 +The exponencial of 12 is 144 +The exponencial of 14 is 196 +The exponencial of 16 is 256 +The exponencial of 18 is 324 + +*/ \ No newline at end of file diff --git a/week-2/InClass/exercise-I.js b/week-2/InClass/exercise-I.js index e69de29b..42bd53b0 100644 --- a/week-2/InClass/exercise-I.js +++ b/week-2/InClass/exercise-I.js @@ -0,0 +1,28 @@ +const fruits = ['banana', 'apple', 'strawberry', 'kiwi', 'fig', 'orange']; + +console.log( fruits[2]) +console.log( fruits[3]) +console.log( fruits[5]) +console.log( fruits[0]) +console.log( fruits[2]) + +/* prints: + +strawberry +kiwi +orange +banana +strawberry + +*/ + +fruits[1] = "rapberry" +fruits[4] = " pineapple" + +console.log(fruits); + +/* it prints: + +[ 'banana', 'rapberry', 'strawberry', 'kiwi', ' pineapple', 'orange' ] + +*/ \ No newline at end of file diff --git a/week-2/InClass/exercise-J.js b/week-2/InClass/exercise-J.js index 1c14afe9..e7044e94 100644 --- a/week-2/InClass/exercise-J.js +++ b/week-2/InClass/exercise-J.js @@ -1,6 +1,20 @@ + +/* + +Complete this function so that, +if the second index in the array contains the name "Amy", + it returns "Second index matched!" + +*/ + +const people = ["Cristiane", "Juliana", "Amy", "Jorge", "Luis"] + function secondMatchesAmy(array) { - if ( ) { + if ( array[2] === "Amy") { return "Second index matched!"; } return "Second index not matched"; -} \ No newline at end of file +} + console.log(secondMatchesAmy(people)); + + // printa: Second index matched! \ No newline at end of file diff --git a/week-2/InClass/exercise-K.js b/week-2/InClass/exercise-K.js index e69de29b..51460046 100644 --- a/week-2/InClass/exercise-K.js +++ b/week-2/InClass/exercise-K.js @@ -0,0 +1,20 @@ +const students = [ "Cris", "Jane", "Lucas", "Fabricio", "Juan", "Gabriel"] + + + for ( let i = 0; i < students.length ; i++ ){ + const nameofStudent = students[i] + console.log(nameofStudent) + } + + /* + + Prints: + +Cris +Jane +Lucas +Fabricio +Juan +Gabriel + + */ \ No newline at end of file diff --git a/week-3/.DS_Store b/week-3/.DS_Store new file mode 100644 index 00000000..5b6a87d4 Binary files /dev/null and b/week-3/.DS_Store differ diff --git a/week-3/Extra/2-bush-berries.js b/week-3/Extra/2-bush-berries.js index aca45ad5..bc8d3bc2 100644 --- a/week-3/Extra/2-bush-berries.js +++ b/week-3/Extra/2-bush-berries.js @@ -10,10 +10,19 @@ Use the tests to confirm which message to return */ -function bushChecker() { - +function bushChecker(_array) { + if (typeof _array == 'string'.length === 4 && _array.startsWith('p')) + return true + else false } +/* Prints: working on it + +bushChecker funtion works - case 1: FAILED: expected: 'Toxic! Leave bush alone!' but your function returned: undefined +bushChecker funtion works - case 1: FAILED: expected: 'Bush is safe to eat from' but your function returned: undefined + +*/ + /* ======= TESTS - DO NOT MODIFY ===== */ let bushBerryColours1 = ["pink", "pink", "pink", "neon", "pink", "transparent"] diff --git a/week-3/Homework/A-array-find/exercise.js b/week-3/Homework/A-array-find/exercise.js index d7fd51f8..b6af656d 100644 --- a/week-3/Homework/A-array-find/exercise.js +++ b/week-3/Homework/A-array-find/exercise.js @@ -7,9 +7,22 @@ var names = ["Rakesh", "Antonio", "Alexandra", "Andronicus", "Annam", "Mikey", "Anastasia", "Karim", "Ahmed"]; +// function isLongNameStartingWithA(name){ +// return isLongName(name) && startsWithA(name) +// } + +function isLongNameStartingWithA(name){ +return name[0] ==="A" && name.length > 7 + +} + +function findLongNameThatStartsWithA(names){ + return names.find( name => isLongNameStartingWithA(name)) +} + var longNameThatStartsWithA = findLongNameThatStartsWithA(names); console.log(longNameThatStartsWithA); /* EXPECTED OUTPUT */ -// "Alexandra" +// "Alexandra" diff --git a/week-3/Homework/B-array-some/exercise.js b/week-3/Homework/B-array-some/exercise.js index 965c0524..8e2b00fd 100644 --- a/week-3/Homework/B-array-some/exercise.js +++ b/week-3/Homework/B-array-some/exercise.js @@ -10,15 +10,28 @@ var pairsByIndex = [[0, 3], [1, 2], [2, 1], null, [3, 0]]; // If there is a null value in the array exit the program with the error code // https://nodejs.org/api/process.html#process_process_exit_code -// process.exit(1); +if (pairsByIndex.some(item => item == null))process.exit(1); var students = ["Islam", "Lesley", "Harun", "Rukmini"]; var mentors = ["Daniel", "Irina", "Mozafar", "Luke"]; -var pairs = pairsByIndex.map(function(indexes) { +var pairs = pairsByIndex.map(function (indexes) { var student = students[indexes[0]]; var mentor = mentors[indexes[1]]; return [student, mentor]; }); console.log(pairs); + +// prints ( when I delete the null of the program:) + +/* + +[ + [ 'Islam', 'Luke' ], + [ 'Lesley', 'Mozafar' ], + [ 'Harun', 'Irina' ], + <1 empty item>, + [ 'Rukmini', 'Daniel' ] + +]*/ diff --git a/week-3/Homework/C-array-every/exercise.js b/week-3/Homework/C-array-every/exercise.js index b515e941..0574751a 100644 --- a/week-3/Homework/C-array-every/exercise.js +++ b/week-3/Homework/C-array-every/exercise.js @@ -5,7 +5,11 @@ var students = ["Omar", "Austine", "Dany", "Swathi", "Lesley", "Rukmini"]; var group = ["Austine", "Dany", "Swathi", "Daniel"]; -var groupIsOnlyStudents; // complete this statement +function isStudent(name){ + return students.includes(name) +} + +var groupIsOnlyStudents = group.every(isStudent) if (groupIsOnlyStudents) { console.log("The group contains only students"); diff --git a/week-3/Homework/D-array-filter/exercise.js b/week-3/Homework/D-array-filter/exercise.js index 6e32cc6b..401de69f 100644 --- a/week-3/Homework/D-array-filter/exercise.js +++ b/week-3/Homework/D-array-filter/exercise.js @@ -6,17 +6,41 @@ - Do not edit any of the existing code */ -var pairsByIndexRaw = [[0, 3], [1, 2], [2, 1], null, [1], false, "whoops"]; +var pairsByIndexRaw = [[0, 3], [1, 2], [2, 1], null, [1], false, 'whoops']; -var pairsByIndex; // Complete this statement +// Solution 1: -var students = ["Islam", "Lesley", "Harun", "Rukmini"]; -var mentors = ["Daniel", "Irina", "Mozafar", "Luke"]; +/* +var pairsByIndex = pairsByIndexRaw.filter(function (element) { + if (Array.isArray(element) && element.length === 2) { + return true; + } + return false; + +}); +*/ + +// Solution 2: + +// var pairsByIndex = pairsByIndexRaw.filter(element => Array.isArray(element) && element.length === 2); -var pairs = pairsByIndex.map(function(indexes) { +// Solution 3: + +let filterFunction = element => Array.isArray(element) && element.length === 2; +var pairsByIndex = pairsByIndexRaw.filter(filterFunction) + + +var students = ['Islam', 'Lesley', 'Harun', 'Rukmini']; +var mentors = ['Daniel', 'Irina', 'Mozafar', 'Luke']; + +var pairs = pairsByIndex.map(function (indexes) { var student = students[indexes[0]]; var mentor = mentors[indexes[1]]; return [student, mentor]; }); console.log(pairs); + +// Prints: + +//[ [ 'Islam', 'Luke' ], [ 'Lesley', 'Mozafar' ], [ 'Harun', 'Irina' ] ] \ No newline at end of file diff --git a/week-3/Homework/E-array-map/exercise.js b/week-3/Homework/E-array-map/exercise.js index 2835e922..24fbca12 100644 --- a/week-3/Homework/E-array-map/exercise.js +++ b/week-3/Homework/E-array-map/exercise.js @@ -3,3 +3,34 @@ var numbers = [0.1, 0.2, 0.3, 0.4, 0.5]; +//solution 1 - callback function: + +/* +let numbersMultiplied = numbers.map(function (number){ + return number * 100 +}) + +console.log(numbersMultiplied) // prints: [ 10, 20, 30, 40, 50 ] + +*/ + +//solution 2 +/* + +let numbersMultiplied = numbers.map(number => { + return number * 100 +}) + +console.log(numbersMultiplied) // prints: [ 10, 20, 30, 40, 50 ] +*/ + +//solution 3 + + +let numbersMultiplied = numbers.map(number => number * 100) + +console.log(numbersMultiplied) // prints: [ 10, 20, 30, 40, 50 ] + + + + diff --git a/week-3/Homework/F-array-forEach/exercise.js b/week-3/Homework/F-array-forEach/exercise.js index e83e2df6..ff60ce04 100644 --- a/week-3/Homework/F-array-forEach/exercise.js +++ b/week-3/Homework/F-array-forEach/exercise.js @@ -9,6 +9,50 @@ var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]; +// solution 1 + + +arr.forEach(function (element) { + + if (element % 3 === 0 && element % 5 === 0) { + console.log("FizzBuzz"); + } else if (element % 5 === 0) { + console.log("Buzz"); + } else if(element % 3 === 0) { + console.log("Fizz"); + } else { + console.log(element); + } +}); + + +// function solutionTwo(element) { + +// if (element % 3 === 0 && element % 5 === 0) { +// console.log("FizzBuzz"); +// return +// } +// if (element % 5 === 0) { +// console.log("Buzz"); +// return +// } +// if(element % 3 === 0) { +// console.log("Fizz"); +// return +// } +// console.log(element); + +// }; + +// arr.forEach(solutionTwo) + + +// return - "stop the execution of the function // sinonimus of exit - go out of the function" + +// return - IF Theres any expression after >> it will give me undefined + +// if I want to save the result of the function, I can put this on a variable + /* EXPECTED OUTPUT */ /* @@ -28,3 +72,5 @@ var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]; 14 'FizzBuzz' */ + + diff --git a/week-3/Homework/G-array-methods/exercise.js b/week-3/Homework/G-array-methods/exercise.js index 44e9c801..56fa5f24 100644 --- a/week-3/Homework/G-array-methods/exercise.js +++ b/week-3/Homework/G-array-methods/exercise.js @@ -4,7 +4,7 @@ */ var numbers = [3, 2, 1]; -var sortedNumbers; // complete this statement +var sortedNumbers = numbers.sort(); /* DO NOT EDIT BELOW THIS LINE @@ -17,3 +17,8 @@ console.log(sortedNumbers); --------------- [1, 2, 3] */ + + +// Prints: + + [1, 2, 3] \ No newline at end of file diff --git a/week-3/Homework/G-array-methods/exercise2.js b/week-3/Homework/G-array-methods/exercise2.js index 3dd24a17..180cdbb7 100644 --- a/week-3/Homework/G-array-methods/exercise2.js +++ b/week-3/Homework/G-array-methods/exercise2.js @@ -7,7 +7,7 @@ var mentors = ["Daniel", "Irina", "Rares"]; var students = ["Rukmini", "Abdul", "Austine", "Swathi"]; -var everyone; // complete this statement +var everyone = mentors.concat(students) /* DO NOT EDIT BELOW THIS LINE @@ -20,3 +20,15 @@ console.log(everyone); --------------- ["Daniel", "Irina", "Rares", "Rukmini", "Abdul", "Austine", "Swathi"] */ + + +// prints: + +/* + 'Daniel', 'Irina', + 'Rares', 'Rukmini', + 'Abdul', 'Austine', + 'Swathi' +] + +*/ \ No newline at end of file diff --git a/week-3/Homework/H-array-methods-2/exercise.js b/week-3/Homework/H-array-methods-2/exercise.js index d36303b8..1eab436c 100644 --- a/week-3/Homework/H-array-methods-2/exercise.js +++ b/week-3/Homework/H-array-methods-2/exercise.js @@ -15,8 +15,8 @@ var everyone = [ "Swathi" ]; -var firstFive; // complete this statement -var lastFive; // complete this statement +var firstFive = everyone.slice(0,5); +var lastFive =everyone.slice(2,7); /* DO NOT EDIT BELOW THIS LINE diff --git a/week-3/Homework/H-array-methods-2/exercise2.js b/week-3/Homework/H-array-methods-2/exercise2.js index b7be576e..bd9060ca 100644 --- a/week-3/Homework/H-array-methods-2/exercise2.js +++ b/week-3/Homework/H-array-methods-2/exercise2.js @@ -7,7 +7,16 @@ Tip: use the string method .split() and the array method .join() */ -function capitalise(str) {} +//First solution + +function capitalise(str) { + return str.charAt(0).toUpperCase() + str.slice(1) +} + +// Prints +// Daniel +// Hello + /* DO NOT EDIT BELOW THIS LINE diff --git a/week-3/Homework/H-array-methods-2/exercise3.js b/week-3/Homework/H-array-methods-2/exercise3.js index 82e9dd8c..8084d195 100644 --- a/week-3/Homework/H-array-methods-2/exercise3.js +++ b/week-3/Homework/H-array-methods-2/exercise3.js @@ -6,8 +6,9 @@ var ukNations = ["Scotland", "Wales", "England", "Northern Ireland"]; + function isInUK(country) { - return; // complete this statement + return ukNations.includes(country); } /* @@ -18,7 +19,7 @@ console.log(isInUK("Republic of Ireland")); console.log(isInUK("England")); /* - EXPECTED RESULT + EXPECTED RESULT // printed: --------------- false false diff --git a/week-3/InClass/exercise-A.js b/week-3/InClass/exercise-A.js index e69de29b..f962aa96 100644 --- a/week-3/InClass/exercise-A.js +++ b/week-3/InClass/exercise-A.js @@ -0,0 +1,17 @@ +let peopleOnMyTable = ["Cristiane", "Rosangela", "Marina"]; + +console.log(peopleOnMyTable, peopleOnMyTable.length); + +// prints : + +// 'Cristiane', 'Rosangela', 'Marina' ] 3 + +peopleOnMyTable.unshift("Felix"); // Añade el nombre al inicio del array +peopleOnMyTable.push('SomeoneElse') // Añade el nombre al final del Array + + +console.log(peopleOnMyTable); + +// prints : + +// [ 'Felix', 'Cristiane', 'Rosangela', 'Marina', 'SomeoneElse' ] diff --git a/week-3/InClass/exercise-B.js b/week-3/InClass/exercise-B.js index e69de29b..c87db744 100644 --- a/week-3/InClass/exercise-B.js +++ b/week-3/InClass/exercise-B.js @@ -0,0 +1,43 @@ +let peopleOnMyClass = ["Cristiane" , "Valeria" , "Diego" , "Alejandra" , "Yennifer" , "Angel "]; + +let peopleFromTheOtherClass = peopleOnMyClass.concat("Yogi ", "Diana ", "Abdul ", "Carlos ", "Vincent ", "David ") + +console.log(peopleFromTheOtherClass.sort()) + + +/* prints +[ + 'Abdul ', 'Alejandra', + 'Angel ', 'Carlos', + 'Cristiane ', 'David', + 'Diana', 'Diego', + 'Valeria', 'Vincent', + 'Yennifer', 'Yogi' +] +*/ + +// function callingByTheName(people){ +// if (peopleOnMyClass == people) { +// return `${people} is at the class with ${peopleOnMyClass}` +// } +// return `${people} is not at the class with ${peopleOnMyClass}` + +// } + + + +// prints: + +// Vincent is not at the class with Cristiane,Valeria,Diego,Alejandra,Yennifer,Angel + +function callingByTheName(name, arr){ + if (!arr.includes(name)){ + return `${name} is not at the class with ${peopleOnMyClass}` + } + return `${name} is at the class with ${peopleOnMyClass}` +} + +console.log(callingByTheName("Juan", peopleFromTheOtherClass)) + + +// prints: Juan is not at the class with Cristiane,Valeria,Diego,Alejandra,Yennifer,Angel \ No newline at end of file diff --git a/week-3/InClass/exercise-C.js b/week-3/InClass/exercise-C.js index e69de29b..03668b1a 100644 --- a/week-3/InClass/exercise-C.js +++ b/week-3/InClass/exercise-C.js @@ -0,0 +1,50 @@ + + +// I have a function defined below as: +// This function does not need to be modified. Can you pass in a callback function which will mutate namesArray such that it: +// Upper cases all letters in the array + +function magician(yourFunc) { + console.log("I am magician! Watch as I mutate an array of strings to your heart's content!"); + const namesArray = [ + "James", + "Elamin", + "Ismael", + "Sanyia", + "Chris", + "Antigoni", + ]; + + const magicOutput = yourFunc(namesArray); + + return magicOutput; +} + +// const upperCaseNamesArray = function (yourFunc){ return namesArray.toUpperCase()} + +/// + +function nametoUpperCase(person){ + return person.toUpperCase(); +} + +function manipulateArray(array){ + const result = [] + for (let i = 0; i < array.length; i++){ + const element = array[i]; + result.push(nametoUpperCase(element)) + } + return result; +} + +console.log(magician(manipulateArray)) + + +/// It prints: + +//I am magician! Watch as I mutate an array of strings to your heart's content! +//[ 'JAMES', 'ELAMIN', 'ISMAEL', 'SANYIA', 'CHRIS', 'ANTIGONI' ] + + + + diff --git a/week-3/InClass/exercise-D.js b/week-3/InClass/exercise-D.js index e69de29b..83b8171c 100644 --- a/week-3/InClass/exercise-D.js +++ b/week-3/InClass/exercise-D.js @@ -0,0 +1,47 @@ + + +/* Modify your callback function from the previous exercise so that it also: +sorts namesArray in alphabetical order */ + +function magician(yourFunc) { + console.log( + "I am magician! Watch as I mutate an array of strings to your heart's content!" + ); + const namesArray = [ + "James", + "Elamin", + "Ismael", + "Sanyia", + "Chris", + "Antigoni", + ]; + + const magicOutput = yourFunc(namesArray); + + return magicOutput; +} + +// const upperCaseNamesArray = function (yourFunc){ return namesArray.toUpperCase()} + +/// + +function nametoUpperCase(person){ + return person.toUpperCase(); +} + +function manipulateArray(array){ + const result = [] + for (let i = 0; i < array.length; i++){ + const element = array[i]; + result.push(nametoUpperCase(element)) + } + return result.sort(); +} + +console.log(magician(manipulateArray)) + + +//Prints: + +//I am magician! Watch as I mutate an array of strings to your heart's content! +//[ 'ANTIGONI', 'CHRIS', 'ELAMIN', 'ISMAEL', 'JAMES', 'SANYIA' ] diff --git a/week-3/InClass/exercise-E.js b/week-3/InClass/exercise-E.js index e69de29b..4642a61e 100644 --- a/week-3/InClass/exercise-E.js +++ b/week-3/InClass/exercise-E.js @@ -0,0 +1,28 @@ + +/* + +Create a function that takes a birthYear, and returns the age of someone +You are given an array with year that 7 people were born, [1964, 2008, 1999, 2005, 1978, 1985, 1919]. +Take this array and create another array containing their ages. +console.log the birth years array + +*/ + +const birthYears = [1964, 2008, 1999, 2005, 1978, 1985, 1919]; + +const ages = birthYears.map(function (birthYear){ + const year = 2022; + const yearsOld = year - birthYear; + return yearsOld + +}) + +console.log(ages) + +/* RESULT +[ + 58, 14, 23, 17, + 44, 37, 103 +] + +*/ diff --git a/week-3/InClass/exercise-F.js b/week-3/InClass/exercise-F.js index e69de29b..f5e86fdf 100644 --- a/week-3/InClass/exercise-F.js +++ b/week-3/InClass/exercise-F.js @@ -0,0 +1,39 @@ +/* +You can drive in the UK at the age of 17. + +Write another function that takes a birth year and returns a string Born in {year} + can drive or Born in {year} can drive in {x} years + +Use the array of birth years, [ 1964, 2008, 1999, 2005, 1978, 1985, 1919 ], + to get an array of strings saying if these people can drive + +console.log the answers +*/ + +const birthYears = [1964, 2008, 1999, 2005, 1978, 1985, 1919]; + + +const dLicense = birthYears.map(function (birthYear){ + const year = 2022; // number + const yearsOld = year - birthYear; // number + const yearsWaiting = 17 - yearsOld; // number + if ( yearsOld < 17){ + console.log(`Born in ${birthYear} can drive in ${yearsWaiting} years`) + } else if( yearsOld >= 17) + console.log( `Born in ${birthYear} can drive`) + }); + + +//PRINTS: + +/* + +Born in 1964 can drive +Born in 2008 can drive in 3 years +Born in 1999 can drive +Born in 2005 can drive +Born in 1978 can drive +Born in 1985 can drive +Born in 1919 can drive + +*/ \ No newline at end of file diff --git a/week-3/InClass/exercise-G.js b/week-3/InClass/exercise-G.js index e69de29b..f2938915 100644 --- a/week-3/InClass/exercise-G.js +++ b/week-3/InClass/exercise-G.js @@ -0,0 +1,24 @@ +/* + +Create a function which: +Takes an array of birthYears +Uses console.log to print the message +These are the birth years of people who can drive: +Returns an array of people who can drive (remember, you can drive if you are 17 years or older) + +*/ + +const birthYears = [1964, 2008, 1999, 2005, 1978, 1985, 1919]; + +function whoCanDrive(birthYear){ + return birthYear <= 2005; +} + +const canDrive = birthYears.filter(whoCanDrive) + +console.log(`These are the birth years of people who can drive ${canDrive}`); + + +//prints: + +// These are the birth years of people who can drive 1964,1999,2005,1978,1985,1919 diff --git a/week-3/InClass/exercise-H.js b/week-3/InClass/exercise-H.js index e69de29b..5e5c52f2 100644 --- a/week-3/InClass/exercise-H.js +++ b/week-3/InClass/exercise-H.js @@ -0,0 +1,33 @@ +/* + +Exercise H (10 mins) +Create a function which: +Takes an array of names +Looks to see if your name is in the array +If it is, return Found me!; if not, return Haven't found me :( + +*/ + +const nameList = ["Cristiane", "Joana", "Carmem" , "Maria", "Ana"]; + +// I did in two ways, this first one I was not happy about it: + +// function findingPeople(nameList){ +// if (nameList === "Cristiane") // boolean +// return "Found me!" +// else +// return "Haven't found me" +// } +// console.log(findingPeople("Cristiane")) + +// I Kept practicing, and I found this new way a little bit easier now, and I can use properly an array method ( better than put my name dirrectly at the function): + +const findingPeople = (nameList) => { + if (nameList.includes(nameList)){ + return "Found me!" + } else + return "Haven't found me" +} + +console.log(findingPeople("Cristiane")) // prints: Found me! + diff --git a/week-3/InClass/exercise-I.js b/week-3/InClass/exercise-I.js index e69de29b..a2ba607e 100644 --- a/week-3/InClass/exercise-I.js +++ b/week-3/InClass/exercise-I.js @@ -0,0 +1,56 @@ +/* +Create a function which accepts an array of "messy" strings. Example: +[ + 100, + "iSMael", + 55, + 45, + "sANyiA", + 66, + "JaMEs", + "eLAmIn", + 23, + "IsMael", + 67, + 19, + "ElaMIN", +]; + +This function should: +Remove all non-string entries +Change the strings to upper case, and add an exclamation mark to the end +If you're using the above example, you should expect to return an array with 2x ELAMIN!, 1x SANYIA!, 2x ISMAEL! and 1x JAMES! + +*/ + const messyElements = [ + 100, + "iSMael", + 55, + 45, + "sANyiA", + 66, + "JaMEs", + "eLAmIn", + 23, + "IsMael", + 67, + 19, + "ElaMIN", +]; + + +const stringArray = messyElements.forEach( function organizingElements(element){ + if (typeof element === 'string'){ + console.log(element.toLocaleUpperCase() + '!') + } }) + +// printa : +// ISMAEL! +// SANYIA! +// JAMES! +// ELAMIN! +// ISMAEL! +// ELAMIN! + + +