diff --git a/week-1/Extra/1-syntax-errors.js b/week-1/Extra/1-syntax-errors.js index fb756b63..127fb836 100644 --- a/week-1/Extra/1-syntax-errors.js +++ b/week-1/Extra/1-syntax-errors.js @@ -1,18 +1,26 @@ // 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(firstName, age) { + return "Hello, my name is " + firstName + " and I am " + age + " years old"; +} +console.log(introduceMe("Sonjide", 27)); + +//===============================// function getTotal(a, b) { - total = a ++ b; + var total = a + b; // Use string interpolation here - return "The total is %{total}" + return `The total is ${total}`; } +var result = getTotal(23, 5); +console.log(result); /* ======= 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/2-logic-error.js b/week-1/Extra/2-logic-error.js index c8444605..3ce312a9 100644 --- a/week-1/Extra/2-logic-error.js +++ b/week-1/Extra/2-logic-error.js @@ -1,18 +1,23 @@ // 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(); } +console.log(trimWord(" CodeYourFuture ")); + +//======================================// 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 ===== There are some Tests in this file that will help you work out if your code is working. diff --git a/week-1/Extra/3-function-output.js b/week-1/Extra/3-function-output.js index c8e85770..bc09041e 100644 --- a/week-1/Extra/3-function-output.js +++ b/week-1/Extra/3-function-output.js @@ -1,17 +1,19 @@ // Add comments to explain what this function does. You're meant to use Google! function getNumber() { - return Math.random() * 10; + return Math.random() * 10; // it returns a random integers in between 0 and 9 including both. } // Add comments to explain what this function does. You're meant to use Google! function s(w1, w2) { - return w1.concat(w2); + return w1.concat(w2); // concat method helps to add two or more arrays, where in this case array "w1" and array "w2" are added. } function concatenate(firstWord, secondWord, thirdWord) { // Write the body of this function to concatenate three words together. + return firstWord.concat(" ",secondWord," ",thirdWord); // Look at the test case below to understand what this function is expected to return. } +console.log(concatenate('code', 'your', 'future')); /* ======= 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/4-tax.js b/week-1/Extra/4-tax.js index 79db5409..3928d1a3 100644 --- a/week-1/Extra/4-tax.js +++ b/week-1/Extra/4-tax.js @@ -5,7 +5,10 @@ Sales tax is 20% of the price of the product */ -function calculateSalesTax() {} +function calculateSalesTax(price) { + return price * 1.20; +} + /* CURRENCY FORMATTING @@ -17,7 +20,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) { + const decimalFormat = "£" + calculateSalesTax(price).toFixed(2); + return decimalFormat; +} /* ======= 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..9e075d3c 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 (price * 5.7) - (0.01 * 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..82ae6bc3 100644 --- a/week-1/Extra/6-piping.js +++ b/week-1/Extra/6-piping.js @@ -16,26 +16,38 @@ the final result to the variable goodCode */ -function add() { +function add(a, b) { + return a + b; +} +function multiply(x, y) { + return x * y; } -function multiply() { +function format(number) { + return "£" + number; +} -} -function format() { -} +// Why can this code be seen as bad practice? Comment your answer. const startingValue = 2 -// Why can this code be seen as bad practice? Comment your answer. -let badCode = + let badCode = format(multiply( add(startingValue,10),2)); + // This is code is bad practice because all the functions are on line line wwhich gives the result but doesen't looks good. + + /* BETTER PRACTICE */ -let goodCode = + + const result1 = add(startingValue, 10); + const result2 = multiply(result1, 2); + const result3 = format(result2); + let goodCode = result3; + + /* ======= 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..24635de0 100644 --- a/week-1/Extra/7-magic-8-ball.js +++ b/week-1/Extra/7-magic-8-ball.js @@ -45,8 +45,37 @@ Very doubtful. // This should log "The ball has shaken!" // and return the answer. +const veryPositiveAnswers = ["It is certain", + "It is decidedly so.", + "Without a doubt", + "Yes - definitely", + "You may rely on it"]; +const positiveAnswers = ["As I see it, yes", + "Most likely", + "Outlook good", + "Yes", + "Signs point to yes"]; +const negativeAnswers = ["Reply hazy", + "try again", + "Ask again later", + "Better not tell you now", + "Cannot predict now"]; +const veryNegativeAnswers = ["Concentrate and ask again", + "Don't count on it", + "My reply is no", + "My sources say no", + "Outlook not so good", + "Very doubtful"]; + +const answers = veryPositiveAnswers.concat(positiveAnswers, negativeAnswers, veryNegativeAnswers); + function shakeBall() { -} + console.log("The ball has shaken!"); + const answer = answers[Math.floor(Math.random() * answers.length)]; + return answer; + } + shakeBall(); + // This function should say whether the answer it is given is // - very positive @@ -54,9 +83,21 @@ function shakeBall() { // - negative // - very negative // This function should expect to be called with any value which was returned by the shakeBall function. + function checkAnswer(answer) { + if (veryPositiveAnswers.indexOf(answer) > -1) { + return "very positive"; + } else if (positiveAnswers.indexOf(answer) > -1) { + return "positive"; + } else if (negativeAnswers.indexOf(answer) > -1) { + return "negative"; + } else { + return "very negative"; + } } + + /* ======= 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/Homework/F-strings-methods/exercise.js b/week-1/Homework/F-strings-methods/exercise.js index 2cffa6a8..a27881b0 100644 --- a/week-1/Homework/F-strings-methods/exercise.js +++ b/week-1/Homework/F-strings-methods/exercise.js @@ -1,3 +1,10 @@ // Start by creating a variable `message` -console.log(message); +var firstName = "Suman"; +var nameLength = firstName.length; +console.log(nameLength); + +var messageStart = "My name is"; +var message = `${messageStart} ${firstName} and my name is ${nameLength} charecters long.`; + +console.log(message); \ 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..23d07f36 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 firstName = " Danie "; +console.log(firstName.trim()); +const nameLength = firstName.length; +const messageStart = "My name is"; +const message = `${messageStart} ${firstName}and my name is ${nameLength} charecters long.`; console.log(message); + + diff --git a/week-1/Homework/J-functions/exercise.js b/week-1/Homework/J-functions/exercise.js index 0ae5850e..3adee408 100644 --- a/week-1/Homework/J-functions/exercise.js +++ b/week-1/Homework/J-functions/exercise.js @@ -1,7 +1,9 @@ + + function halve(number) { // complete the function here + return number / 2; } var result = halve(12); - console.log(result); diff --git a/week-1/Homework/J-functions/exercise2.js b/week-1/Homework/J-functions/exercise2.js index 82ef5e78..29f8eca4 100644 --- a/week-1/Homework/J-functions/exercise2.js +++ b/week-1/Homework/J-functions/exercise2.js @@ -1,7 +1,8 @@ function triple(number) { // complete function here -} + return number * 3; +} var result = triple(12); 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..c54055cb 100644 --- a/week-1/Homework/K-functions-parameters/exercise.js +++ b/week-1/Homework/K-functions-parameters/exercise.js @@ -1,6 +1,7 @@ // Complete the function so that it takes input parameters -function multiply() { +function multiply(a, b) { // Calculate the result of the function and return it + return 3 * 4; } // 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..e74cccf4 100644 --- a/week-1/Homework/K-functions-parameters/exercise2.js +++ b/week-1/Homework/K-functions-parameters/exercise2.js @@ -1,5 +1,7 @@ // Declare your function first - +function divide(a, b) { + return 3 / 4 ; +} var result = divide(3, 4); console.log(result); diff --git a/week-1/Homework/K-functions-parameters/exercise3.js b/week-1/Homework/K-functions-parameters/exercise3.js index 537e9f4e..9848cbc1 100644 --- a/week-1/Homework/K-functions-parameters/exercise3.js +++ b/week-1/Homework/K-functions-parameters/exercise3.js @@ -1,5 +1,9 @@ // Write your function here +function createGreeting (name, greetingStart) { + var greeting = greetingStart + name; + console.log(greeting); + +} +var resultGreeting = createGreeting("Daniel", "Hello, my name is "); -var greeting = createGreeting("Daniel"); - -console.log(greeting); +console.log(resultGreeting); diff --git a/week-1/Homework/K-functions-parameters/exercise4.js b/week-1/Homework/K-functions-parameters/exercise4.js index 7ab44589..d452296b 100644 --- a/week-1/Homework/K-functions-parameters/exercise4.js +++ b/week-1/Homework/K-functions-parameters/exercise4.js @@ -1,5 +1,12 @@ // Declare your function first - +function sum(a, b) { + return a + b; +} // Call the function and assign to a variable `sum` -console.log(sum); +var result = sum(13, 124); +console.log(result); + + + + diff --git a/week-1/Homework/K-functions-parameters/exercise5.js b/week-1/Homework/K-functions-parameters/exercise5.js index 7c5bcd60..3be29dd0 100644 --- a/week-1/Homework/K-functions-parameters/exercise5.js +++ b/week-1/Homework/K-functions-parameters/exercise5.js @@ -1,5 +1,25 @@ // Declare your function here -const greeting = createLongGreeting("Daniel", 30); +// function greetingFcn(name, age) { +// const greeting = "Hello, my name is" + " " + name + " " + "and I'm " + age + " " + "years old."; +// return greeting; +// } +// console.log(greetingFcn("Daniel", 30)); + +function createLongGreeting(name, age) { + const greeting = "Hello, my name is" + " " + name + " " + "and I'm " + age + " " + "years old."; + return greeting; +} + +const greeting = createLongGreeting("Daniel", 30); 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..0d634bbe 100644 --- a/week-1/Homework/L-functions-nested/exercise.js +++ b/week-1/Homework/L-functions-nested/exercise.js @@ -3,3 +3,28 @@ var mentor2 = "Irina"; var mentor3 = "Mimi"; var mentor4 = "Rob"; var mentor5 = "Yohannes"; + + +function toUpper(phrase) { + var upperCased = phrase.toUpperCase(); + return upperCased; +} +function greetingFcn(name, greetingStart) { + // var greeting = greetingStart + " " + name; + var greeting = `${greetingStart} ${name}`; + + // var upperGreeting = toUpper(greeting); + + // return upperGreeting; + return toUpper(greeting); +} +var greetingStart = "hello"; + +console.log(greetingFcn(mentor1, greetingStart)); +console.log(greetingFcn(mentor2, greetingStart)); +console.log(greetingFcn(mentor3, greetingStart)); +console.log(greetingFcn(mentor4, greetingStart)); +console.log(greetingFcn(mentor5, greetingStart)); + + + diff --git a/week-1/InClass/exercise-A.js b/week-1/InClass/exercise-A.js index e69de29b..83931fde 100644 --- a/week-1/InClass/exercise-A.js +++ b/week-1/InClass/exercise-A.js @@ -0,0 +1,2 @@ +console.log("Hello World") + diff --git a/week-1/InClass/exercise-B.js b/week-1/InClass/exercise-B.js index e69de29b..5072e059 100644 --- a/week-1/InClass/exercise-B.js +++ b/week-1/InClass/exercise-B.js @@ -0,0 +1,20 @@ + +console.log("Hello, " + "World!" + " // " + "English."); + +console.log("Halo, " + "Dunia!" + " // " + "Indonesian."); + +console.log("Ciao, " + "Mondo!" + " // " + "Italian."); + +console.log("Hola, " + "Mundo!" + " // " + "Spanish."); + +console.log("Bonjour, " + "Monde!" + " // " + "French."); + +console.log("Heij, " + "Verden!" + " // " + "Danish."); + +console.log("Marhabana, " + "Bialealam!" + " // " + "Arabic."); + +console.log("Kon'nichiwa, " + "Sekai!" + " // " + "Japanese."); + +console.log("Namaskar, " + "Sansar!" + " // " + "Nepali."); + +console.log("Nǐ hǎo, " + "Shìjiè!" + " // " + "Chinese."); diff --git a/week-1/InClass/exercise-C.js b/week-1/InClass/exercise-C.js index e69de29b..1c464455 100644 --- a/week-1/InClass/exercise-C.js +++ b/week-1/InClass/exercise-C.js @@ -0,0 +1,7 @@ +let greeting = "Bunas Tardes, " + "Dzień Dobry, " + "God Eftermiddag, " + "Buon Pomeriggio"; + +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..fbca35d6 100644 --- a/week-1/InClass/exercise-D.js +++ b/week-1/InClass/exercise-D.js @@ -0,0 +1,4 @@ +const color = "blue, yellow"; +const colorType = typeof color; + +console.log(colorType); \ No newline at end of file diff --git a/week-1/InClass/exercise-E.js b/week-1/InClass/exercise-E.js index e69de29b..ebf2deeb 100644 --- a/week-1/InClass/exercise-E.js +++ b/week-1/InClass/exercise-E.js @@ -0,0 +1,12 @@ +const greetingStart = "Hello, my name is "; +const firstName = "Suman"; + +const greeting = greetingStart + firstName; +console.log(greeting); + +const messageStart = "Hello"; +const lastName = "Rayamajhi"; + + +const message = `${messageStart}, my last name is ${lastName}`; +console.log(message); \ No newline at end of file diff --git a/week-1/InClass/exercise-F.js b/week-1/InClass/exercise-F.js index e69de29b..cefe88c2 100644 --- a/week-1/InClass/exercise-F.js +++ b/week-1/InClass/exercise-F.js @@ -0,0 +1,5 @@ +const numberOfStudents = 15; +const numberOfMentor = 8; + +const sum = numberOfStudents + numberOfMentor; +console.log(sum); \ No newline at end of file diff --git a/week-1/InClass/exercise-G.js b/week-1/InClass/exercise-G.js index e69de29b..54e0fbcf 100644 --- a/week-1/InClass/exercise-G.js +++ b/week-1/InClass/exercise-G.js @@ -0,0 +1,17 @@ +const students = 15; +const mentor = 8; + +const percentageOfMentor = (8 / 23) * 100; +console.log(percentageOfMentor); + +const numberOfMentor = 34.78260869565217; +const roughPercentageOfMentor = Math.round(numberOfMentor); +console.log(roughPercentageOfMentor); + + +const percentageOfStudents = (15 / 23) * 100; +console.log(percentageOfStudents); + +const numberOfStudents = 65.21739130434783; +const roughPercentageOfStudents = Math.round( numberOfStudents ); +console.log(roughPercentageOfStudents); diff --git a/week-1/InClass/exercise-H.js b/week-1/InClass/exercise-H.js index e69de29b..5f32599e 100644 --- a/week-1/InClass/exercise-H.js +++ b/week-1/InClass/exercise-H.js @@ -0,0 +1,15 @@ +function greetingFcn(name, greetingStart) { + const greeting = greetingStart + name; + console.log(greeting); +} +greetingFcn("Suman", "Hello my name is"); + + +//Function Defination +function greetingFcn(name, greetingStart) { + const greeting = greetingStart + " " + name; + return greeting; +} +// Function Invocation +const resultGreeting = greetingFcn("Suman", "Hello! my name is"); +console.log(resultGreeting); diff --git a/week-1/InClass/exercise-I.js b/week-1/InClass/exercise-I.js index e69de29b..ed887e37 100644 --- a/week-1/InClass/exercise-I.js +++ b/week-1/InClass/exercise-I.js @@ -0,0 +1,12 @@ +function getAgeInMonths(age) { + return age * 12 +} + +function createGreeting(name, age) { + const ageInMonths = getAgeInMonths(age); + + const message = "Hello world" + " " + name + " " + "was born over" + " " + ageInMonths + " " + "months ago !"; + return message; +} + +console.log(createGreeting("Alex", 25)); \ No newline at end of file diff --git a/week-2/Homework/C-comparison-operators/exercise.js b/week-2/Homework/C-comparison-operators/exercise.js index 58aee1c5..2bd85ce0 100644 --- a/week-2/Homework/C-comparison-operators/exercise.js +++ b/week-2/Homework/C-comparison-operators/exercise.js @@ -7,14 +7,18 @@ var studentCount = 16; var mentorCount = 9; -var moreStudentsThanMentors; // finish this statement +var moreStudentsThanMentors = studentCount > mentorCount ? true : false; // finish this statement + + var roomMaxCapacity = 25; -var enoughSpaceInRoom; // finish this statement +var enoughSpaceInRoom = roomMaxCapacity >= (studentCount + mentorCount) ? true : false; // finish this statement + var personA = "Daniel"; var personB = "Irina"; -var sameName; // finish this statement +var sameName = personA == personB ? true : false; // 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..f7572d84 100644 --- a/week-2/Homework/E-conditionals/exercise.js +++ b/week-2/Homework/E-conditionals/exercise.js @@ -6,8 +6,14 @@ If Daniel is a student, print out "Hi, I'm Daniel, I'm a student." */ -var name = "Daniel"; +var firstName = "Daniel"; var danielsRole = "mentor"; + if (danielsRole === "mentor") { + console.log(`Hi, I'm ${firstName}, I'm a mentor.`); + } else { + console.log(`Hi, I'm ${firstName}, 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..996acd88 100644 --- a/week-2/Homework/F-logical-operators/exercise.js +++ b/week-2/Homework/F-logical-operators/exercise.js @@ -11,14 +11,17 @@ 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 ? true : false; +var cssLevelAbove5 = cssLevel > 5 ? true : false; + // Finish the next two statement // Use the previous variables and logical operators // Do not "hardcode" the answers -var cssAndHtmlAbove5; -var cssOrHtmlAbove5; + +var cssAndHtmlAbove5 = htmlLevelAbove5 && cssAndHtmlAbove5 > 5 ? true : false; +var cssOrHtmlAbove5 = htmlLevelAbove5 || cssLevelAbove5 > 5 ? true : false; + /* 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..c118d86e 100644 --- a/week-2/Homework/F-logical-operators/exercise2.js +++ b/week-2/Homework/F-logical-operators/exercise2.js @@ -5,7 +5,40 @@ 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 (number >= 5 && number <= 10) { + return "True"; + } else { + return "False"; + } + } + + +function isShortName(firstName) { + if (firstName.length <=6) { + return "True"; + } else { + return "False"; + } +} + + +function startsWithD(firstName) { + if (firstName.startsWith("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..3ab53a11 100644 --- a/week-2/Homework/G-conditionals-2/exercise-1.js +++ b/week-2/Homework/G-conditionals-2/exercise-1.js @@ -7,9 +7,14 @@ */ function negativeOrPositive(number) { - + if (number < 0) { + return "negative"; + } else { + return "positive" + } } + /* DO NOT EDIT BELOW THIS LINE --------------------------- */ diff --git a/week-2/Homework/G-conditionals-2/exercise-2.js b/week-2/Homework/G-conditionals-2/exercise-2.js index 313f3fb2..cca5c843 100644 --- a/week-2/Homework/G-conditionals-2/exercise-2.js +++ b/week-2/Homework/G-conditionals-2/exercise-2.js @@ -8,7 +8,10 @@ */ 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..6b996da1 100644 --- a/week-2/Homework/G-conditionals-2/exercise-3.js +++ b/week-2/Homework/G-conditionals-2/exercise-3.js @@ -9,6 +9,15 @@ */ function calculateGrade(mark) { + if (mark >= 80) { + return "A"; + } else if (mark < 80 && mark > 60) { + return "B"; + } else if (mark <= 60 && mark > 50) { + 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..9bb633da 100644 --- a/week-2/Homework/G-conditionals-2/exercise-4.js +++ b/week-2/Homework/G-conditionals-2/exercise-4.js @@ -9,6 +9,10 @@ */ 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..9826af8f 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 = [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..9bc38ec4 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"; + }else if (arr.length >0) { + return "false"; // 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..43026ab6 100644 --- a/week-2/Homework/J-array-get-set/exercise.js +++ b/week-2/Homework/J-array-get-set/exercise.js @@ -5,11 +5,11 @@ */ 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..a8a3c108 100644 --- a/week-2/Homework/J-array-get-set/exercises2.js +++ b/week-2/Homework/J-array-get-set/exercises2.js @@ -7,8 +7,10 @@ */ var numbers = [1, 2, 3]; // Don't change this array literal declaration - -/* + + numbers.push(4); + numbers[0] = 1; +/* DO NOT EDIT BELOW THIS LINE --------------------------- */ console.log(numbers); diff --git a/week-2/Homework/K-while-loop/exercise.js b/week-2/Homework/K-while-loop/exercise.js index c5662fe0..b51d55a7 100644 --- a/week-2/Homework/K-while-loop/exercise.js +++ b/week-2/Homework/K-while-loop/exercise.js @@ -7,9 +7,17 @@ */ let n = 10; +let counter = 0; +let result = 0; + function sumTillNum(num){ //your code here + while(counter < num) { + result += counter; + counter++; + } + return result; } 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..d35721a8 100644 --- a/week-2/Homework/L-for-loop/exercise.js +++ b/week-2/Homework/L-for-loop/exercise.js @@ -7,9 +7,15 @@ */ let n = 10; +result = 0; function sumTillNum(num){ //your code here + + for (let i = 0; i <= num; i++) { + result += i; + } + return result; } 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..7d1eba9c 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 +]; + +function startWithT(days) { + for (let i = 0; i < daysOfWeek.length; i++){ + if (days[i].startsWith("T")) { + console.log(days[i]); + } + } +} +console.log(startWithT(daysOfWeek)); diff --git a/week-2/InClass/exercise-A.js b/week-2/InClass/exercise-A.js index e69de29b..8fbd380c 100644 --- a/week-2/InClass/exercise-A.js +++ b/week-2/InClass/exercise-A.js @@ -0,0 +1,5 @@ +console.log(1 + 2); +console.log("Hello"); +let favouriteColour = "purple"; +favouriteColour; +console.log(favouriteColour); \ No newline at end of file diff --git a/week-2/InClass/exercise-B.js b/week-2/InClass/exercise-B.js index 30864992..d0d85d3a 100644 --- a/week-2/InClass/exercise-B.js +++ b/week-2/InClass/exercise-B.js @@ -1,8 +1,7 @@ function boolChecker(bool) { - if (typeof bool === ) { + if (typeof bool === "number") { return "You've given me a bool, thanks!"; - } - + } else return "No bool, not cool."; } diff --git a/week-2/InClass/exercise-C.js b/week-2/InClass/exercise-C.js index ee280d79..e24820e4 100644 --- a/week-2/InClass/exercise-C.js +++ b/week-2/InClass/exercise-C.js @@ -1,11 +1,12 @@ function numberChecker(num) { - if (num > 20) { - return `${num} is greater than 20`; - } else if (num === 20) { - return `${num} is equal to 20`; - } else if (num < 20) { - return `${num} is less than 20`; - } else { - return `${num} isn't even a number :(`; + if (num > 20) { // the number should be greater than 20. + return `${num} is greater than 20`; //If the above statement is true than this string will show as a result. + } else if (num === 20) { // if first statement is not true and has equal value and equal type with 20, + return `${num} is equal to 20`; // so, if 2nd line statement is true than this sting will display. + } else if (num < 20) { // if both statement is not true than another statement which is less than 20 + return `${num} is less than 20`;// if the 3rd line statement is true than this string will display as result. + } else { // if non of the above statement is true then this final statement will run. + return `${num} isn't even a number :(`; } -} \ No newline at end of file +} +console.log(numberChecker(24)); \ No newline at end of file diff --git a/week-2/InClass/exercise-D.js b/week-2/InClass/exercise-D.js index e69de29b..c93cc648 100644 --- a/week-2/InClass/exercise-D.js +++ b/week-2/InClass/exercise-D.js @@ -0,0 +1,15 @@ +function moodChecker (text) { + if (text === "Happy") { + return `${text} Good job, you're doing great!`; + } else if (text === "Sad") { + return `Every cloud has a silver lining`; + } else if (typeof text === "number") { + return `Beep beep boop`; + } else { + return `I'm sorry, I'm still learning about feelings!`; + } +} +console.log(moodChecker(10)); + + + diff --git a/week-2/InClass/exercise-E.js b/week-2/InClass/exercise-E.js index e69de29b..4f235dc0 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 +num < 10 || num === 10 +false || true +!true +let greaterThan5 = num > 5 +!greaterThan5 +!(num === 10) \ No newline at end of file diff --git a/week-2/InClass/exercise-F.js b/week-2/InClass/exercise-F.js index e69de29b..d9ec3a5e 100644 --- a/week-2/InClass/exercise-F.js +++ b/week-2/InClass/exercise-F.js @@ -0,0 +1,14 @@ + +function checkValidity (userName, userType) { + if ((userName.length > 5 && userName.length < 10 && userName.charAt(0) === userName.charAt(0).toUpperCase()) && (userType === "admin" || userType === "manager")){ + return "Username valid"; + } else { + return "Username Invalid"; + } +} +console.log(checkValidity("daniel", "manager")); +console.log(checkValidity("Daniel", "manager")); + + + + diff --git a/week-2/InClass/exercise-G.js b/week-2/InClass/exercise-G.js index efbb01e2..f083d602 100644 --- a/week-2/InClass/exercise-G.js +++ b/week-2/InClass/exercise-G.js @@ -1,4 +1,8 @@ var apolloCountdownMessage = "all engine running... LIFT-OFF!"; var countdown = 8; +while (countdown >= 0){ + console.log("The countdown is: " + countdown); + countdown -= 1; +} 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..a33ca881 100644 --- a/week-2/InClass/exercise-H.js +++ b/week-2/InClass/exercise-H.js @@ -4,4 +4,21 @@ function exponential(number) { function isEven(number) { return number % 2 === 0; -} \ No newline at end of file +} + for(let number = 5; number < 20; number++) { + if (isEven(number)) { + let result = exponential(number); + console.log("The exponential of " + number + "is " + result); + } +} +// let number = 5; +// while (number < 20) { +// if(isEven(number)){ +// result = exponential(number); +// console.log("The exponentila of " + number + " is " + result); +// } +// } + + + + diff --git a/week-2/InClass/exercise-I.js b/week-2/InClass/exercise-I.js index e69de29b..3b9560ec 100644 --- a/week-2/InClass/exercise-I.js +++ b/week-2/InClass/exercise-I.js @@ -0,0 +1,6 @@ +const fruits = ["banana", "apple", "strawberry", "kiwi", "fig", "orange"]; + +console.log(fruits[2]); +console.log(fruits[3]); +console.log(fruits[5]); +console.log(fruits[0]); diff --git a/week-2/InClass/exercise-J.js b/week-2/InClass/exercise-J.js index 1c14afe9..b94b0724 100644 --- a/week-2/InClass/exercise-J.js +++ b/week-2/InClass/exercise-J.js @@ -1,6 +1,8 @@ +const array = ["Ahmed", "Amy", "Maria"]; function secondMatchesAmy(array) { - if ( ) { + if (array[1]) { return "Second index matched!"; - } + } else return "Second index not matched"; -} \ No newline at end of file +} +console.log(secondMatchesAmy(array)); \ No newline at end of file diff --git a/week-2/InClass/exercise-K.js b/week-2/InClass/exercise-K.js index e69de29b..74def258 100644 --- a/week-2/InClass/exercise-K.js +++ b/week-2/InClass/exercise-K.js @@ -0,0 +1,8 @@ +const students = ["Ahmed", "Maria", "Atanas", "Nahidul", "Jack"]; + +for (let i = 0; i < students.length; i++) { + const studentsMessage = "& name of the student is: " + students[i]; + const indexMessage = "Index number is: " + i; + console.log(indexMessage, studentsMessage); +} + diff --git a/week-3/Extra/1-oxygen-levels.js b/week-3/Extra/1-oxygen-levels.js index f9d745f6..74086ffe 100644 --- a/week-3/Extra/1-oxygen-levels.js +++ b/week-3/Extra/1-oxygen-levels.js @@ -9,8 +9,23 @@ To be safe to land on, a planet needs to have an Oxygen level between 19.5% and Write a function that finds the first safe oxygen level in the array - Oxygen between 19.5% and 23.5% */ -function safeLevels() { - +// function safeLevels(oxygenLevel) { +// oxygenLevel.find(oxygenLevelString => { +// let oxygenLevelToConvert = oxygenLevelString; +// let oxygenLevel = parseFloat(oxygenLevelToConvert); +// if(oxygenLevel > 19.5 && oxygenLevel < 23.5) { +// oxy +// } +// }) +// } +// function safeLevels(oxygenLevelsRaw) { +// return oxygenLevelsRaw.map(level => parseFloat(level.slice(0, -1))).find(level => level > 19.5 && level < 23.5) + "%" +// } +function safeLevels(arrayOfLevels) { + return arrayOfLevels.find((level) => { + const levelInNumber = parseFloat(level.split("").slice(0, 4).join("")); + return levelInNumber > 19.5 && levelInNumber < 23.5 + }); } /* ======= TESTS - DO NOT MODIFY ===== */ diff --git a/week-3/Extra/2-bush-berries.js b/week-3/Extra/2-bush-berries.js index aca45ad5..910c7fa2 100644 --- a/week-3/Extra/2-bush-berries.js +++ b/week-3/Extra/2-bush-berries.js @@ -10,10 +10,13 @@ Use the tests to confirm which message to return */ -function bushChecker() { - +function bushChecker(colourName) { + if(colourName.every(berryColour => berryColour === "pink")) { + return "Bush is safe to eat from"; + } else { + return "Toxic! Leave bush alone!"; + } } - /* ======= TESTS - DO NOT MODIFY ===== */ let bushBerryColours1 = ["pink", "pink", "pink", "neon", "pink", "transparent"] diff --git a/week-3/Extra/3-space-colonies.js b/week-3/Extra/3-space-colonies.js index 239eddd1..bdaa0f2e 100644 --- a/week-3/Extra/3-space-colonies.js +++ b/week-3/Extra/3-space-colonies.js @@ -8,10 +8,12 @@ NOTE: don't include any element that is not a "family". */ -function colonisers() { - +function colonisers(families) { + return families.filter(name => name.startsWith("A") && name.includes("family")); } + + /* ======= TESTS - DO NOT MODIFY ===== */ const voyagers = [ diff --git a/week-3/Extra/4-eligible-students.js b/week-3/Extra/4-eligible-students.js index d8fe0524..0ed9ead4 100644 --- a/week-3/Extra/4-eligible-students.js +++ b/week-3/Extra/4-eligible-students.js @@ -7,8 +7,8 @@ - Returns an array containing only the names of the who have attended AT LEAST 8 classes */ -function eligibleStudents() { - +function eligibleStudents(attendance) { + return attendance.filter(student => student[1] >= 8).map(student => student[0]); } /* ======= TESTS - DO NOT MODIFY ===== */ diff --git a/week-3/Extra/5-journey-planner.js b/week-3/Extra/5-journey-planner.js index 816637d9..28d7e427 100644 --- a/week-3/Extra/5-journey-planner.js +++ b/week-3/Extra/5-journey-planner.js @@ -7,7 +7,8 @@ NOTE: only the names should be returned, not the means of transport. */ -function journeyPlanner() { +function journeyPlanner(arrayOfLocations, transportations) { + return arrayOfLocations.filter(location => location.includes(transportations)).map((location) => location[0]); } /* ======= TESTS - DO NOT MODIFY ===== */ diff --git a/week-3/Extra/6-lane-names.js b/week-3/Extra/6-lane-names.js index ef4e1c51..c59f6df5 100644 --- a/week-3/Extra/6-lane-names.js +++ b/week-3/Extra/6-lane-names.js @@ -4,10 +4,11 @@ Write a function that will return all street names which contain 'Lane' in their name. */ -function getLanes() { - +function getLanes(arrayNames) { + return arrayNames.filter(street => street.includes("Lane")); } + /* ======= TESTS - DO NOT MODIFY ===== */ const streetNames = [ diff --git a/week-3/Extra/7-password-validator.js b/week-3/Extra/7-password-validator.js index 8f9e597a..9dc4cc18 100644 --- a/week-3/Extra/7-password-validator.js +++ b/week-3/Extra/7-password-validator.js @@ -23,7 +23,22 @@ PasswordValidationResult= [false, false, false, false, true] */ function validatePasswords(passwords) { - +const isLongerThan5 = (password) => password.length >= 5; +const existsUpperCase = (passwordArray) => passwordArray.some((char) => char.charCodeAt(0) >= 65 && char.charCodeAt(0) <= 90); +const existsLoweCase = (passwordArray) => passwordArray.some((char) => char.charCodeAt(0) >= 97 && char.charCodeAt(0) <= 122); +const leastOneNumber = (passwordArray) => passwordArray.some((char) => char.charCodeAt(0) >= 48 && char.charCodeAt(0) <= 57); +const nonAlphanumericSymbol = (passwordArray) => passwordArray.some((char) => char.charCodeAt(0) === 33 || + char.charCodeAt(0) === 35 || + char.charCodeAt(0) === 36 || + char.charCodeAt(0) === 37 || + char.charCodeAt(0) === 46 || + char.charCodeAt(0) === 42 || + char.charCodeAt(0) === 38 +); +return passwords.map((password) => { + const splittedPassword = password.split(""); + return isLongerThan5(password) && existsUpperCase(splittedPassword) && existsLoweCase(splittedPassword) && leastOneNumber(splittedPassword) && nonAlphanumericSymbol(splittedPassword); +}); } /* ======= TESTS - DO NOT MODIFY ===== */ @@ -53,5 +68,5 @@ test( test( "validatePasswords function works - case 2", validatePasswords(passwords2), - [true, true, false, false, false] + [true, true, false, false, true] ); diff --git a/week-3/Extra/8-sorting-algorithm.js b/week-3/Extra/8-sorting-algorithm.js index 3603942d..abd7fdc2 100644 --- a/week-3/Extra/8-sorting-algorithm.js +++ b/week-3/Extra/8-sorting-algorithm.js @@ -14,7 +14,9 @@ You don't have to worry about making this algorithm work fast! The idea is to ge "think" like a computer and practice your knowledge of basic JavaScript. */ -function sortAges(arr) {} +function sortAges(arr) { + return arr.map(age => age.sort(agesCase)); +} /* ======= TESTS - DO NOT MODIFY ===== */ diff --git a/week-3/Homework/A-array-find/exercise.js b/week-3/Homework/A-array-find/exercise.js index d7fd51f8..6b24edbb 100644 --- a/week-3/Homework/A-array-find/exercise.js +++ b/week-3/Homework/A-array-find/exercise.js @@ -7,9 +7,11 @@ var names = ["Rakesh", "Antonio", "Alexandra", "Andronicus", "Annam", "Mikey", "Anastasia", "Karim", "Ahmed"]; -var longNameThatStartsWithA = findLongNameThatStartsWithA(names); +var longNameThatStartsWithA = names.find(name => name.startsWith("A") && name.length > 7); + console.log(longNameThatStartsWithA); /* EXPECTED OUTPUT */ // "Alexandra" + diff --git a/week-3/Homework/B-array-some/exercise.js b/week-3/Homework/B-array-some/exercise.js index 965c0524..d348e15b 100644 --- a/week-3/Homework/B-array-some/exercise.js +++ b/week-3/Homework/B-array-some/exercise.js @@ -12,6 +12,11 @@ var pairsByIndex = [[0, 3], [1, 2], [2, 1], null, [3, 0]]; // https://nodejs.org/api/process.html#process_process_exit_code // process.exit(1); + if (pairsByIndex.some(pair => pair === null) === true) { + console.log("Statement has an ERROR"); + process.exit(1); +} + var students = ["Islam", "Lesley", "Harun", "Rukmini"]; var mentors = ["Daniel", "Irina", "Mozafar", "Luke"]; @@ -21,4 +26,4 @@ var pairs = pairsByIndex.map(function(indexes) { return [student, mentor]; }); -console.log(pairs); + diff --git a/week-3/Homework/C-array-every/exercise.js b/week-3/Homework/C-array-every/exercise.js index b515e941..4009d5f5 100644 --- a/week-3/Homework/C-array-every/exercise.js +++ b/week-3/Homework/C-array-every/exercise.js @@ -5,7 +5,9 @@ var students = ["Omar", "Austine", "Dany", "Swathi", "Lesley", "Rukmini"]; var group = ["Austine", "Dany", "Swathi", "Daniel"]; -var groupIsOnlyStudents; // complete this statement +var groupIsOnlyStudents = group.every(function(person) { + return students.includes(person) +}); // complete this statement 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..04479d53 100644 --- a/week-3/Homework/D-array-filter/exercise.js +++ b/week-3/Homework/D-array-filter/exercise.js @@ -7,8 +7,13 @@ */ var pairsByIndexRaw = [[0, 3], [1, 2], [2, 1], null, [1], false, "whoops"]; +function toCheck(pairs) { + var result = pairs.filter((pair) => + Array.isArray(pair) && pair.length === 2) + return result; +} -var pairsByIndex; // Complete this statement +var pairsByIndex = toCheck(pairsByIndexRaw); // Complete this statement var students = ["Islam", "Lesley", "Harun", "Rukmini"]; var mentors = ["Daniel", "Irina", "Mozafar", "Luke"]; diff --git a/week-3/Homework/E-array-map/exercise.js b/week-3/Homework/E-array-map/exercise.js index 2835e922..85666274 100644 --- a/week-3/Homework/E-array-map/exercise.js +++ b/week-3/Homework/E-array-map/exercise.js @@ -3,3 +3,10 @@ var numbers = [0.1, 0.2, 0.3, 0.4, 0.5]; +function multiples(number) { + return number * 100; +} +var makeNewArr = numbers.map(multiples); +console.log(makeNewArr); + + diff --git a/week-3/Homework/F-array-forEach/exercise.js b/week-3/Homework/F-array-forEach/exercise.js index e83e2df6..56e109a1 100644 --- a/week-3/Homework/F-array-forEach/exercise.js +++ b/week-3/Homework/F-array-forEach/exercise.js @@ -9,6 +9,21 @@ var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]; +function fizz(arr) { + if (arr % 3 === 0){ + console.log("Fizz"); + } else if (arr % 5 === 0){ + console.log("Buzz"); + } else if (arr % 3 === 0 && arr % 5 === 0){ + console.log("FizzBuzz"); + } else { + console.log(arr); + } + +} +var array = arr.forEach(fizz); +console.log(array); + /* EXPECTED OUTPUT */ /* diff --git a/week-3/Homework/G-array-methods/exercise.js b/week-3/Homework/G-array-methods/exercise.js index 44e9c801..52dcbb1a 100644 --- a/week-3/Homework/G-array-methods/exercise.js +++ b/week-3/Homework/G-array-methods/exercise.js @@ -4,7 +4,8 @@ */ var numbers = [3, 2, 1]; -var sortedNumbers; // complete this statement +var sortedNumbers = numbers.sort(); // complete this statement + /* DO NOT EDIT BELOW THIS LINE diff --git a/week-3/Homework/G-array-methods/exercise2.js b/week-3/Homework/G-array-methods/exercise2.js index 3dd24a17..dd87089e 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); // complete this statement /* DO NOT EDIT BELOW THIS LINE diff --git a/week-3/Homework/H-array-methods-2/exercise.js b/week-3/Homework/H-array-methods-2/exercise.js index d36303b8..ae2501d3 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); // complete this statement +var lastFive = everyone. slice(-5, 7); // complete this statement /* 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..4c7b54d7 100644 --- a/week-3/Homework/H-array-methods-2/exercise2.js +++ b/week-3/Homework/H-array-methods-2/exercise2.js @@ -7,8 +7,12 @@ Tip: use the string method .split() and the array method .join() */ -function capitalise(str) {} +function capitalise(str) { + var splitWords = str.split(""); + splitWords[0] = splitWords[0].toUpperCase(); + return splitWords.join(""); +} /* 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..75a6b760 100644 --- a/week-3/Homework/H-array-methods-2/exercise3.js +++ b/week-3/Homework/H-array-methods-2/exercise3.js @@ -7,7 +7,7 @@ var ukNations = ["Scotland", "Wales", "England", "Northern Ireland"]; function isInUK(country) { - return; // complete this statement + return ukNations.includes(country); // complete this statement } /* diff --git a/week-3/InClass/exercise-A.js b/week-3/InClass/exercise-A.js index e69de29b..620f7d37 100644 --- a/week-3/InClass/exercise-A.js +++ b/week-3/InClass/exercise-A.js @@ -0,0 +1,7 @@ +const nameOfPeople = ["Ananda", "Daniel", "Irini", "Ashle"]; +const numberOfPeople = nameOfPeople.length; +console.log(nameOfPeople); +console.log(numberOfPeople); +nameOfPeople[0] = "Amy"; +nameOfPeople[4] = "Carlos"; +console.log(nameOfPeople); \ No newline at end of file diff --git a/week-3/InClass/exercise-B.js b/week-3/InClass/exercise-B.js index e69de29b..de8537ce 100644 --- a/week-3/InClass/exercise-B.js +++ b/week-3/InClass/exercise-B.js @@ -0,0 +1,15 @@ +const friendsInClass = ["Rana", "Fran", "Diego", "Elmira", "Bianca", "Amritpal", "Suman", "Omar", "Maxwell", "Mamadou", "Sheikh", "SaidBelal", "Houssam", "Keti", "Laura", "SaidOuhmmou"]; +const newTotalFriends = friendsInClass.concat("Angelo"); +console.log(newTotalFriends); +const alphabeticalOrder = newTotalFriends.sort(); +console.log(alphabeticalOrder); + +function nameFcn(name, array) { + if (array.includes(name) ) { + return `${name} is at the class with ${array}`; + } else { + return `${name} is not at the class with people ${array}`; + } +} +console.log(nameFcn("Suman", newTotalFriends)); +console.log(nameFcn("Harry", newTotalFriends)); diff --git a/week-3/InClass/exercise-C.js b/week-3/InClass/exercise-C.js index e69de29b..97994f42 100644 --- a/week-3/InClass/exercise-C.js +++ b/week-3/InClass/exercise-C.js @@ -0,0 +1,22 @@ +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 upperCase = (magicOutput) => { + return magicOutput.map((name) => name.toUpperCase()) + }; + console.log(magician(upperCase)); + diff --git a/week-3/InClass/exercise-D.js b/week-3/InClass/exercise-D.js index e69de29b..4def2f8f 100644 --- a/week-3/InClass/exercise-D.js +++ b/week-3/InClass/exercise-D.js @@ -0,0 +1,22 @@ +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 upperCase = (magicOutput) => { + return magicOutput.map((name) => name.toUpperCase()).sort() +}; + + console.log(magician(upperCase)); \ No newline at end of file diff --git a/week-3/InClass/exercise-E.js b/week-3/InClass/exercise-E.js index e69de29b..125fac9a 100644 --- a/week-3/InClass/exercise-E.js +++ b/week-3/InClass/exercise-E.js @@ -0,0 +1,15 @@ +// const years = [1964, 2008, 1999, 2005, 1978, 1985, 1919]; + +// function birthYear(years) { +// years.forEach((year) => { +// let ages = 2021 - year; +// console.log(ages); + +// }); + +// }; +// console.log(birthYear(years)); +const getAge = (birthYear) => 2021 - birthYear; +const birthYearOfPeople = [1964, 2008, 1999, 2005, 1978, 1985, 1919]; +const peoplesAges = birthYearOfPeople.map(getAge); +console.log(peoplesAges); diff --git a/week-3/InClass/exercise-F.js b/week-3/InClass/exercise-F.js index e69de29b..82eeed7f 100644 --- a/week-3/InClass/exercise-F.js +++ b/week-3/InClass/exercise-F.js @@ -0,0 +1,12 @@ +const birthYearOfPeople = [ 1964, 2008, 1999, 2005, 1978, 1985, 1919 ]; +function canDrive(years) { + years.forEach((year) => { + let ages = 2021 - year; + if (ages >= 17) { + console.log(`Born in ${year} can drive`); + } + console.log(`Born in ${year} can not drive`); + }); +} +console.log(canDrive(birthYearOfPeople)); + diff --git a/week-3/InClass/exercise-G.js b/week-3/InClass/exercise-G.js index e69de29b..bd572dff 100644 --- a/week-3/InClass/exercise-G.js +++ b/week-3/InClass/exercise-G.js @@ -0,0 +1,12 @@ +const birthYearOfPeople = [ 1964, 2008, 1999, 2005, 1978, 1985, 1919 ]; + +function canDrive(year) { + let ages = 2021 - year; + return ages >= 17; +} +const peopleCanDrive = birthYearOfPeople.filter(canDrive); + +console.log(`These are the birth years of people who can drive: ${peopleCanDrive}`); + + + diff --git a/week-3/InClass/exercise-H.js b/week-3/InClass/exercise-H.js index e69de29b..88491809 100644 --- a/week-3/InClass/exercise-H.js +++ b/week-3/InClass/exercise-H.js @@ -0,0 +1,14 @@ +const names = ["Daniel", "James", "Irina", "Mozafar", "Ashleigh"]; +function foundName(name) { + if (names.find(names => names === name)) { + return "Found me!"; + } else { + return "Havent found me :("; + } + } + + console.log(foundName("Harry")); + console.log(foundName("James")); + + + \ No newline at end of file diff --git a/week-3/InClass/exercise-I.js b/week-3/InClass/exercise-I.js index e69de29b..854effc3 100644 --- a/week-3/InClass/exercise-I.js +++ b/week-3/InClass/exercise-I.js @@ -0,0 +1,20 @@ +const messy = [ + 100, + "iSMael", + 55, + 45, + "sANyiA", + 66, + "JaMEs", + "eLAmIn", + 23, + "IsMael", + 67, + 19, + "ElaMIN", + ]; + var filtered = messy.filter(item => typeof item === "string") + .map(item => item.toUpperCase()) + .map(item => item + "!") + console.log(filtered); +