parent
baf55ebf99
commit
f8eaa5db1a
@ -0,0 +1,10 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>30DaysOfScript:Internal Script</title>
|
||||
|
||||
<script src="introduction.js"></script>
|
||||
|
||||
</head>
|
||||
<body></body>
|
||||
</html>
|
@ -0,0 +1 @@
|
||||
console.log('Welcome to 30DaysOfJavaScript')
|
@ -0,0 +1,11 @@
|
||||
const webTechs = [
|
||||
'HTML',
|
||||
'CSS',
|
||||
'JavaScript',
|
||||
'React',
|
||||
'Redux',
|
||||
'Node',
|
||||
'MongoDB',
|
||||
]
|
||||
|
||||
module.exports = webTechs
|
@ -0,0 +1,15 @@
|
||||
const countries = [
|
||||
'Albania',
|
||||
'Bolivia',
|
||||
'Canada',
|
||||
'Denmark',
|
||||
'Ethiopia',
|
||||
'Finland',
|
||||
'Germany',
|
||||
'Hungary',
|
||||
'Ireland',
|
||||
'Japan',
|
||||
'Kenya',
|
||||
]
|
||||
|
||||
module.exports = countries
|
@ -0,0 +1,55 @@
|
||||
// Exercise 1 - Level 1
|
||||
|
||||
const webTechs = [
|
||||
'HTML',
|
||||
'CSS',
|
||||
'JavaScript',
|
||||
'React',
|
||||
'Redux',
|
||||
'Node',
|
||||
'MongoDB',
|
||||
]
|
||||
|
||||
const newArray = Array(6).fill('cats');
|
||||
newArray.push(7)
|
||||
|
||||
const itCompanies = Array('Facebook', 'Google', 'Microsoft', 'Apple', 'IBM', 'Oracle', 'Amazon')
|
||||
|
||||
for (let i = 0; i<itCompanies.length; i++) {
|
||||
return (itCompanies[i].toLowerCase())
|
||||
}
|
||||
|
||||
const store = itCompanies.pop()
|
||||
const string = itCompanies.join(', ')
|
||||
const sentence = string + " and " + store + " are big IT Companies."
|
||||
// return sentence
|
||||
|
||||
for (let i = 0; i < itCompanies.length; i++) {
|
||||
let index = itCompanies.indexOf(itCompanies[i])
|
||||
index != -1
|
||||
? console.log('This company does exist in the array')
|
||||
: console.log('This company does not exist in the array')
|
||||
}
|
||||
|
||||
for (let i = 0; i < itCompanies.length; i++) {
|
||||
|
||||
if (itCompanies[i].includes('o')) {
|
||||
let matcher = itCompanies[i].match(/o/g).length
|
||||
if (matcher > 1) {
|
||||
return itCompanies[i]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const sliced = itCompanies.slice(itCompanies.length-3, itCompanies.length)
|
||||
|
||||
const middle = itCompanies[Math.floor((itCompanies.length)/2)]
|
||||
|
||||
const middleIndex = Math.floor((itCompanies.length)/2)
|
||||
|
||||
itCompanies.splice(middleIndex,1)
|
||||
|
||||
itCompanies.length = 0
|
||||
|
||||
|
||||
|
@ -0,0 +1,47 @@
|
||||
// Exercise 1 - Level 2
|
||||
|
||||
const countries = require('./countries.js');
|
||||
const webTechs = require('./ web_techs.js');
|
||||
|
||||
const str = countries.toString()
|
||||
|
||||
const modifiedStr = str.replace(/[^\w]/g, ' ')
|
||||
|
||||
const newArray = modifiedStr.split(' ')
|
||||
|
||||
const numOfWords = newArray.length
|
||||
|
||||
|
||||
const shoppingCart = ['Milk', 'Coffee', 'Tea', 'Honey']
|
||||
|
||||
if (!shoppingCart.includes('Meat')) {
|
||||
shoppingCart.unshift('Meat')
|
||||
}
|
||||
|
||||
if (!shoppingCart.includes('Sugar')) {
|
||||
shoppingCart.push('Sugar')
|
||||
}
|
||||
|
||||
shoppingCart[3] = 'Green Tea'
|
||||
|
||||
|
||||
|
||||
if (!countries.includes('Ethiopia')) {
|
||||
countries.push('Ethiopia')
|
||||
} else {
|
||||
console.log('Ethiopia')
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (!webTechs.includes('Sass')) {
|
||||
webTechs.push('Sass')
|
||||
console.log(webTechs)
|
||||
} else {
|
||||
console.log('Sass is a CSS preprocess')
|
||||
}
|
||||
|
||||
const frontEnd = ['HTML', 'CSS', 'JS', 'React', 'Redux']
|
||||
const backEnd = ['Node', 'Express', 'MongoDB']
|
||||
|
||||
const fullStack = frontEnd.concat(backEnd)
|
@ -0,0 +1,29 @@
|
||||
// Exercise 1 - Level 3
|
||||
|
||||
const countries = require('./countries.js');
|
||||
const ages = [19, 22, 19, 24, 20, 25, 26, 24, 25, 24]
|
||||
|
||||
const sortedArray = ages.sort()
|
||||
|
||||
const minAge = sortedArray[0]
|
||||
const maxAge = sortedArray[sortedArray.length-1]
|
||||
|
||||
const medianAge = (sortedArray[4] + sortedArray[5])/2
|
||||
|
||||
const averageAge = (sortedArray.reduce((number, a) => number + a, 0))/sortedArray.length
|
||||
|
||||
const rangeAge = maxAge - minAge
|
||||
|
||||
const compareAge = (maxAge - averageAge)-(minAge - averageAge)
|
||||
|
||||
|
||||
|
||||
|
||||
const slicedCountries = countries.slice(0,10)
|
||||
|
||||
const middleCountry = countries[5]
|
||||
|
||||
const firstHalf = countries.slice(0,6)
|
||||
|
||||
const secondHalf = countries.slice(6,11)
|
||||
|
@ -0,0 +1,42 @@
|
||||
// Exercise 2 - Level 1
|
||||
|
||||
let age = 34
|
||||
|
||||
if (age <18) {
|
||||
let years = 18 - age
|
||||
console.log(`You have ${years} years left until you can drive.`)
|
||||
} else {
|
||||
console.log(`You are old enough to drive.`)
|
||||
}
|
||||
|
||||
|
||||
if (age > 29) {
|
||||
let years = age - 29
|
||||
console.log(`You are ${years} years older than me.`)
|
||||
} else if (age === 29) {
|
||||
console.log(`You are the same age as me.`)
|
||||
} else {
|
||||
let years = 29 - age
|
||||
console.log(`I am ${years} years older than you.`)
|
||||
}
|
||||
|
||||
|
||||
let a = 2
|
||||
let b = 2
|
||||
|
||||
if (a > b) {
|
||||
console.log(`${a} is greater than ${b}`)
|
||||
} else if (a === b) {
|
||||
console.log(`${a} is equal to ${b}`)
|
||||
} else {
|
||||
console.log(`${b} is greater than ${a}`)
|
||||
}
|
||||
|
||||
|
||||
let number = 10
|
||||
|
||||
if (number%2 === 0) {
|
||||
console.log(`${number} is even.`)
|
||||
} else {
|
||||
console.log(`${number} is odd.`)
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
// Exercise 2 - Level 2
|
||||
|
||||
let score = 75;
|
||||
|
||||
if (score >= 90 && score <= 100) {
|
||||
console.log('A');
|
||||
} else if (score >= 70 && score < 90) {
|
||||
console.log('B');
|
||||
} else if (score >= 60 && score < 70) {
|
||||
console.log('C');
|
||||
} else if (score >= 50 && score < 60) {
|
||||
console.log('D');
|
||||
} else if (score >= 0 && score < 50) {
|
||||
console.log('E');
|
||||
} else {
|
||||
console.log('Invalid score');
|
||||
}
|
||||
|
||||
|
||||
let month = 'September'
|
||||
|
||||
if (month === 'September' || month === 'October' || month === 'November') {
|
||||
console.log('The season is Autumn')
|
||||
} else if (month === 'December' || month === 'January' || month === 'February') {
|
||||
console.log('The season is Winter')
|
||||
} else if (month === 'March' || month === 'April' || month === 'May') {
|
||||
console.log('The season is Spring')
|
||||
} else if (month === 'June' || month === 'July' || month === 'August') {
|
||||
console.log('The season is Summer') }
|
||||
|
||||
|
||||
let day = 'FriDAY'
|
||||
|
||||
let lowered = day.toLowerCase()
|
||||
|
||||
switch(lowered){
|
||||
case 'saturday':
|
||||
console.log('Saturday is a weekend')
|
||||
break
|
||||
case 'sunday':
|
||||
console.log('Sunday is a weekend.')
|
||||
break
|
||||
default:
|
||||
const capital = lowered.slice(0,1).toUpperCase()
|
||||
const capitalised = capital + lowered.slice(1)
|
||||
console.log(`${capitalised} is a week day.`)
|
||||
}
|
||||
|
@ -0,0 +1,16 @@
|
||||
// Exercise 2 - Level 3
|
||||
|
||||
const currentDate = new Date();
|
||||
const currentYear = currentDate.getFullYear();
|
||||
|
||||
let month = 'February'
|
||||
|
||||
if (month === 'April' || month === 'June' || month === 'September'|| month === 'November') {
|
||||
console.log(`${month} has 30 days.`)
|
||||
} else if (month === 'February' && currentYear%4 === 0) {
|
||||
console.log(`February has 29 days.`)
|
||||
} else if (month === 'February' && !currentYear%4 === 0) {
|
||||
console.log(`February has 28 days.`)
|
||||
} else {console.log(`${month} has 31 days.`)}
|
||||
|
||||
|
Loading…
Reference in new issue