console.log(countries) //Exercises Level 1 //Exercise 1 -- Declares an empty array var emptyArray = []; //Exercise 2 -- Declare an array with more than 5 elements var names = ["Brendan", "Jacob", "Chloe", "Katherine", "Nicole", "Sienna"]; //Exercise 3 -- Find the length of your array in #2 and prints it to console var lengthOfArray = names.length console.log(`Length of names array is: ${lengthOfArray}`); //Exercise 4 -- Gets the first, middle, and last item of the array from exercise 3 and print the result to console var firstElement = names[0]; var middleElement; console.log(`First element: ${firstElement}`); (names.length%2==0) ?console.log(`Middle elements are ${names[Math.floor((names.length-1)/2)]} and ${names[Math.ceil((names.length-1)/2)]}`) //value is true :console.log(`${names[((names.length-1)/2)]}`); //value is false var lastElement = names[names.length-1]; console.log(`Last element: ${lastElement}`); //Exercise 5 -- Declare an array called mixedDataTypes, put different data types in //the array and find the length of the array. The array size should be greater than 5 var mixedDataTypes = [1, 2, 3, "myString", "yourString", true, false]; console.log(`Length of mixedDataTypes is ${mixedDataTypes.length}`); //Exercise 6 -- Declares an array named itCompanies and assigned initial values Facebook, Google, Microsoft, Apple, IBM, Oracle and Amazon var itCompanies = ["Facebook","Google","Microsoft","Apple","IBM","Oracle","Amazon"]; //Exercise 7 -- Prints the array using console.log() console.log(itCompanies); //Exercise 8 -- Prints the number of companies in the itCompanies array console.log(`Number of itCompanies is ${itCompanies.length}`); //Exercise 9 -- Prints the first company, middle and last company (from itCompanies) var first = itCompanies[0]; var middle; (itCompanies.length%2==0) ?console.log(`Middle elements are ${itCompanies[Math.floor((itCompanies.length-1)/2)]} and ${itCompanies[Math.ceil((itCompanies.length-1)/2)]}`) //value is true :console.log(`${itCompanies[((itCompanies.length-1)/2)]}`); //value is false var last = itCompanies[itCompanies.length-1]; //Exercise 10 -- Prints out each company for(var i=0;i=0) console.log(`${itCompanies[tempValue]}`); else console.log('The company is not found'); //Exercise 14 -- Filter out companies which have more than one 'o' without the filter method var tempItCompanies = []; var filterCounter = 0; for(var a=0; a=0) console.log(`${(countries[tempIndex]).toUpperCase()}`); //Prints country if found in countries array else { countries.push('Ethiopia'); //Adds to end of array if not found console.log(countries); } //Exercise 5 -- In the webTechs array check if Sass exists in the array and if it exists print 'Sass is a CSS preprocess'. If it does not exist add Sass to the array and print the array. //Uses searchStringInArray function from Exercises Level 1, Exercise 13 and tempIndex from Exercises Level 2, Exercise 4 tempIndex = searchStringInArray('Sass', webTechs); if(tempIndex>=0) console.log('Sass is a CSS preprocess'); else { webTechs.push('Sass'); console.log(webTechs); } //Exercise 6 -- Concatenate the given two variables and store it in a fullStack variable, and prints fullStack to console const frontEnd = ['HTML', 'CSS', 'JS', 'React', 'Redux']; const backEnd = ['Node','Express', 'MongoDB']; const fullStack = frontEnd.concat(backEnd); console.log(fullStack); //Exercises Level 3 //Exercise 1 -- The following is an array of 10 students ages: const ages = [19, 22, 19, 24, 20, 25, 26, 24, 25, 24]; // Sort the array and find the min and max age ages.sort(); console.log(`Min age of students: ${ages[0]} Max age of students: ${ages[ages.length-1]}`); // Find the median age(one middle item or two middle items divided by two) var middleValueHolder = ((ages.length-1)/2); var median = 0; if(ages.length % 2 == 0) median = ((ages[Math.floor(middleValueHolder)]+ages[Math.ceil(middleValueHolder)])/2); else median = ages[Math.floor((ages.length-1)/2)]; //Tested and fully working console.log(median); // Find the average age(all items divided by number of items) var numAgeElements = ages.length; var averageAge = 0; for(var b=0; b