finished level 2. Started level 3

pull/364/head
leon-vay 2 years ago
parent b5716fc91d
commit 2d6f8f825d

@ -1,15 +0,0 @@
const countries = [
'Albania',
'Bolivia',
'Canada',
'Denmark',
'Ethiopia',
'Finland',
'Germany',
'Hungary',
'Ireland',
'Japan',
'Kenya',
]
export { countries };

@ -1,8 +1,29 @@
import { countries } from "./countries";
// import { webTechs } from "./web_tech";
const countries = [
'Albania',
'Bolivia',
'Canada',
'Denmark',
'Ethiopia',
'Finland',
'Germany',
'Hungary',
'Ireland',
'Japan',
'Kenya',
];
const webTechs = [
'HTML',
'CSS',
'JavaScript',
'React',
'Redux',
'Node',
'MongoDB',
]
/**
* EXERCISE: Level 2
* EXERCISE: LEVEL 2
*/
// 1. Create a separate countries.js file and store the countries array into this file,
@ -32,4 +53,23 @@ console.log(shoppingCart);
// 4. In countries array check if 'Ethiopia' exist in the array if it exists print 'ETHIOPIA'. If it does not exist add
// to the countries list
console.log(countries)
if (countries.includes("Ethiopia")) {
console.log('ETHIOPIA');
} else {
countries.push('Ethiopia');
}
// 5. In webTechs array check is 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
if (webTechs.includes('Sass')) {
console.log('Sass is a CSS preprocess');
} else {
webTechs.push('Sass');
console.log(webTechs);
}
// 6. Concatenate the following two variable and store it in a fullStack variable
const frontEnd = ['HTML', 'CSS', 'JS', 'React', 'Redux'];
const backEnd = ['Node', 'Express', 'MongoDB'];
const fullStack = frontEnd.concat(backEnd);
console.log(fullStack);

@ -0,0 +1,59 @@
/**
* EXERCISE: LEVEL 3
*/
const countries = [
'Albania',
'Bolivia',
'Canada',
'Denmark',
'Ethiopia',
'Finland',
'Germany',
'Hungary',
'Ireland',
'Japan',
'Kenya',
]
/**
* 1. The following is an array of 10 students ages.
* - Sort the array and find the min and max age
* - Find the median age(one middle item or two middle items divided by two)
* - Find the average age(all items divided by number of items)
* - Find the range of the ages(max minus min)
* - Compare the value of (min - average) and (max - average), use abs() method
*/
const ages = [19, 22, 19, 24, 20, 25, 26, 24, 25, 24]
ages.sort()
let min = Math.min(...ages)
let max = Math.max(...ages)
let median
if (ages.length % 2 === 0) {
median = (ages[ages.length / 2] + ages[ages.length / 2 - 1]) / 2
} else {
median = ages[ages.length / 2]
}
let sum = 0
for (let i = 0; i < ages.length; i++) {
sum += ages[i]
}
let average = sum / ages.length
let range = Math.max(...ages) - Math.min(...ages)
// 2. Slice the first ten coutries from the countries array
let firstTen = countries.slice(10)
// 3. Find the middle countries in the countries array
let middleCountries = countries[Math.floor(countries.length / 2)]
// 4. Divide the countries array into two equal arrays if it is even. If countries is not even, one more country for the first half
let middle = Math.floor((countries.length - 1) / 2)
const firstHalf = countries.splice(0, middle)
const secondHalf = countries.splice(-middle)

@ -1,11 +0,0 @@
const webTechs = [
'HTML',
'CSS',
'JavaScript',
'React',
'Redux',
'Node',
'MongoDB',
];
export { webTechs };

@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<head>
<title>Solutions Tester</title>
</head>
<body>
<script src="day-01/level3.js"></script>
</body>
</html>
Loading…
Cancel
Save