parent
de083fd5a1
commit
f6e6a844ec
@ -0,0 +1,41 @@
|
||||
const ages = [19, 22, 19, 24, 20, 25, 26, 24, 25, 24];
|
||||
|
||||
// Sort the array and find the min and max age
|
||||
ages.sort((a, b) => a - b);
|
||||
const minAge = ages[0];
|
||||
const maxAge = ages[ages.length - 1];
|
||||
|
||||
// Find the median age (one middle item or two middle items divided by two)
|
||||
const middleIndex = Math.floor(ages.length / 2);
|
||||
const medianAge = ages.length % 2 === 0 ? (ages[middleIndex - 1] + ages[middleIndex]) / 2 : ages[middleIndex];
|
||||
|
||||
// Find the average age (all items divided by number of items)
|
||||
const sumOfAges = ages.reduce((total, age) => total + age, 0);
|
||||
const averageAge = sumOfAges / ages.length;
|
||||
|
||||
// Find the range of the ages (max minus min)
|
||||
const ageRange = maxAge - minAge;
|
||||
|
||||
// Compare the value of (min - average) and (max - average), use abs() method
|
||||
const diffMinAverage = Math.abs(minAge - averageAge);
|
||||
const diffMaxAverage = Math.abs(maxAge - averageAge);
|
||||
|
||||
console.log(`Sorted array of ages: ${ages}`);
|
||||
console.log(`Minimum age: ${minAge}`);
|
||||
console.log(`Maximum age: ${maxAge}`);
|
||||
console.log(`Median age: ${medianAge}`);
|
||||
console.log(`Average age: ${averageAge}`);
|
||||
console.log(`Age range: ${ageRange}`);
|
||||
console.log(`Absolute difference between minimum age and average age: ${diffMinAverage}`);
|
||||
console.log(`Absolute difference between maximum age and average age: ${diffMaxAverage}`);
|
||||
|
||||
|
||||
|
||||
const firstTenCountries = countries.slice(0, 10);
|
||||
const midd = Math.floor(countries.length / 2);
|
||||
const middleCountry = countries[midd];
|
||||
|
||||
|
||||
const halfLength = Math.ceil(countries.length / 2);
|
||||
const firstHalf = countries.slice(0, halfLength);
|
||||
const secondHalf = countries.slice(halfLength);
|
@ -1,6 +1,45 @@
|
||||
import * as countries from './countries';
|
||||
import * as webtech from './web_techs';
|
||||
const countries = require('./countries')
|
||||
const webTechs = require('./web_techs.js')
|
||||
|
||||
console.log(webTechs)
|
||||
|
||||
let text = 'I love teaching and empowering people I teach HTML CSS JS React Python'
|
||||
|
||||
const text_arr = text.split(" ")
|
||||
console.log(text_arr + "\n" + text_arr.length)
|
||||
|
||||
let shoppingCart = ['Milk', 'Coffee', 'Tea', 'Honey']
|
||||
shoppingCart.unshift("Meat")
|
||||
shoppingCart.pop()
|
||||
shoppingCart[3] = "Green Tea"
|
||||
shoppingCart.push("Sugar")
|
||||
|
||||
|
||||
let num = countries.indexOf("Ethiopia")
|
||||
|
||||
if (num = -1) {
|
||||
countries.push("ethiopia")
|
||||
console.log(countries)
|
||||
}
|
||||
else{
|
||||
console.log("ETHIOPIA")
|
||||
}
|
||||
|
||||
|
||||
let tech_num = webTechs.indexOf("Sass")
|
||||
|
||||
|
||||
if (tech_num = -1){
|
||||
webTechs.push("Sass")
|
||||
console.log(webTechs)
|
||||
}
|
||||
else{
|
||||
console.log("Sass is a css process")
|
||||
}
|
||||
|
||||
|
||||
const frontEnd = ['HTML', 'CSS', 'JS', 'React', 'Redux']
|
||||
const backEnd = ['Node', 'Express', 'MongoDB']
|
||||
|
||||
const fullStack = frontEnd.concat(backEnd)
|
||||
|
||||
console.log(fullStack)
|
@ -0,0 +1,30 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Document</title>
|
||||
</head>
|
||||
<body>
|
||||
<script>
|
||||
let usrnum = prompt("Enter a number: ")
|
||||
|
||||
if (usrnum%2 == 0) {
|
||||
console.log("this is an even number")
|
||||
}else{
|
||||
console.log("this is an odd number")
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,41 @@
|
||||
/*let age = prompt("Enter your age: ")
|
||||
|
||||
if (age >= 18){
|
||||
console.log("you are old enough to drive")
|
||||
}else {
|
||||
let diff = 18 - age
|
||||
console.log(`You are ${diff} years from driving`)
|
||||
}
|
||||
|
||||
|
||||
let myage = 20
|
||||
|
||||
if (myage > age){
|
||||
let agediff = myage - age
|
||||
console.log(`I am ${agediff} older than you`)
|
||||
}else{
|
||||
let agediff = age - myage
|
||||
console.log(`You are ${agediff} older than me`)
|
||||
}
|
||||
*/
|
||||
|
||||
let a = 4
|
||||
let b = 3
|
||||
|
||||
if (a > b){
|
||||
console.log("a is greater than b\n")
|
||||
}else{
|
||||
console.log("a is less than b")
|
||||
}
|
||||
|
||||
|
||||
a > b ? console.log("a is greater than b") : console.log("a is less than b")
|
||||
|
||||
|
||||
let usrnum = prompt("Enter a number: ")
|
||||
|
||||
if (usrnum/2 == 0) {
|
||||
console.log("this is an even number")
|
||||
}else{
|
||||
console.log("this is an odd number")
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
function getGrade(score) {
|
||||
var grade;
|
||||
switch (true) {
|
||||
case score >= 80:
|
||||
grade = 'A';
|
||||
break;
|
||||
case score >= 70:
|
||||
grade = 'B';
|
||||
break;
|
||||
case score >= 60:
|
||||
grade = 'C';
|
||||
break;
|
||||
case score >= 50:
|
||||
grade = 'D';
|
||||
break;
|
||||
default:
|
||||
grade = 'F';
|
||||
}
|
||||
return grade;
|
||||
}
|
||||
|
||||
|
||||
function getSeason(month) {
|
||||
var season;
|
||||
switch (month) {
|
||||
case 'September':
|
||||
case 'October':
|
||||
case 'November':
|
||||
season = 'Autumn';
|
||||
break;
|
||||
case 'December':
|
||||
case 'January':
|
||||
case 'February':
|
||||
season = 'Winter';
|
||||
break;
|
||||
case 'March':
|
||||
case 'April':
|
||||
case 'May':
|
||||
season = 'Spring';
|
||||
break;
|
||||
case 'June':
|
||||
case 'July':
|
||||
case 'August':
|
||||
season = 'Summer';
|
||||
break;
|
||||
default:
|
||||
season = 'Invalid month';
|
||||
}
|
||||
return season;
|
||||
}
|
||||
|
||||
|
||||
function isWeekend(day) {
|
||||
var weekend = ['Saturday', 'Sunday'];
|
||||
return weekend.includes(day);
|
||||
}
|
||||
|
@ -0,0 +1,4 @@
|
||||
function daysInMonth(month, year) {
|
||||
return new Date(year, month, 0).getDate();
|
||||
}
|
||||
|
Loading…
Reference in new issue