01 Day activities

pull/327/head
Dan.Kapustin 2 years ago
parent d0c066fcb9
commit aec1241685

@ -0,0 +1,14 @@
const countries = [
'Albania',
'Bolivia',
'Canada',
'Denmark',
'Ethiopia',
'Finland',
'Germany',
'Hungary',
'Ireland',
'Japan',
'Kenya',
]

@ -0,0 +1,60 @@
//Declare an empty array;
const emptyArray = Array()
console.log('Declare an empty array;: Empty array '+emptyArray)
//Declare an array with more than 5 number of elements
const arrayOfSixElements = [1, 2, 3, 4, 5, 6, 7, 8, 9]
console.log('Declare an array with more than 5 number of elements: '+arrayOfSixElements)
//Find the length of your array
const arrayLength = arrayOfSixElements.length
console.log('Find the length of your array: '+arrayLength)
//Get the first item, the middle item and the last item of the array
console.log('First item '+arrayOfSixElements[0])
let middleIndex=Math.round(arrayLength/2)
console.log('Middle item '+arrayOfSixElements[middleIndex])
console.log('Last item '+arrayOfSixElements[arrayLength-1])
//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
const mixedDataTypes=['apple', 3, true, 3.14, 9.8, 'speed']
console.log(mixedDataTypes)
/*
Declare an array variable name itCompanies and assign initial values Facebook, Google, Microsoft, Apple, IBM, Oracle and Amazon
Print the array using console.log()
Print the number of companies in the array
Print the first company, middle and last company
Print out each company
*/
const itCompanies=['Facebook', 'Google', 'Microsoft', 'Apple', 'IBM', 'Oracle', 'Amazon']
console.log(itCompanies)
console.log(itCompanies.length)
console.log(itCompanies[0])
console.log(itCompanies[Math.round(itCompanies.length/2)])
console.log(itCompanies[itCompanies.length-1])
console.log(itCompanies.join(', '))
//Change each company name to uppercase one by one and print them out
//Print the array like as a sentence: Facebook, Google, Microsoft, Apple, IBM,Oracle and Amazon are big IT companies.
/*
Print the array like as a sentence: Facebook, Google, Microsoft, Apple, IBM,Oracle and Amazon are big IT companies.
Check if a certain company exists in the itCompanies array. If it exist return the company else return a company is not found
Filter out companies which have more than one 'o' without the filter method
Sort the array using sort() method
Reverse the array using reverse() method
Slice out the first 3 companies from the array
Slice out the last 3 companies from the array
Slice out the middle IT company or companies from the array
Remove the first IT company from the array
Remove the middle IT company or companies from the array
Remove the last IT company from the array
Remove all IT companies
*/

@ -0,0 +1,40 @@
console.log('Conditions. Ex Level 1.')
let age=prompt('Enter your age:', 0)
console.log('Enter your age: '+age)
if (age>=18) {
console.log('You are old enough to drive.')
} else {
console.log('You are left with 3 years to drive.')
}
let score=prompt('Enter your scores:', 0)
console.log('Enter your scores: '+score)
if (score >= 0 && score <= 49) {
console.log('You score is F.')
} else if (score >= 50 && score <= 59) {
console.log('You score is D.')
} else if (score >= 60 && score <= 69) {
console.log('You score is C.')
} else if (score >= 70 && score <= 89) {
console.log('You score is B.')
} else if (score >= 90 && score <= 100) {
console.log('You score is A.')
}
let month=prompt('Enter a month:', 0)
console.log('Enter a month (English full name): '+month)
switch (month.toUpperCase()) {
//January has 31 days.
case 'JANUARY'||'MARCH'||'MAY'||'JULY'||'AUGUST'||'OCTOBER'||'DECEMBER':
console.log(month[0].toUpperCase()+month.slice(1)+' has 31 days')
break
case 'FEBRUARY':
console.log(month[0].toUpperCase()+month.slice(1)+' has 28/29 days')
break
case 'APRIL'||'JUNE'||'SEPTEMBER'||'NOVEMBER':
console.log(month[0].toUpperCase()+month.slice(1)+' has 30 days')
break
}

@ -0,0 +1,40 @@
let text =
'I love teaching and empowering people. I teach HTML, CSS, JS, React, Python.'
text=text.replace(',', '')
text=text.replace('.', '')
let words=text.split(' ')
console.log(words)
console.log(words.length)
//
const shoppingCart = ['Milk', 'Coffee', 'Tea', 'Honey']
console.log(shoppingCart)
//add 'Meat' in the beginning of your shopping cart if it has not been already added
if (!shoppingCart.includes('Meat')) {
shoppingCart.unshift('Meat')
}
console.log(shoppingCart)
//add Sugar at the end of you shopping cart if it has not been already added
if (!shoppingCart.includes('Sugar')) {
shoppingCart.push('Sugar')
}
console.log(shoppingCart)
//remove 'Honey' if you are allergic to honey
let isHoneyAllergic=true
if (isHoneyAllergic) {
if (shoppingCart.indexOf('Honey')>-1) {
shoppingCart.splice(shoppingCart.indexOf('Honey'), 1)
}
}
console.log(shoppingCart)
//modify Tea to 'Green Tea'
let index=shoppingCart.indexOf('Tea')
if (index>-1) {
shoppingCart[index]='Green Tea'
}
console.log(shoppingCart)

@ -0,0 +1,26 @@
console.log('Function Exercises')
function solveQuadratic (a=0, b=0, c=0) {
console.log('a='+a+', b='+b+', c='+c)
let x1
let x2
let D = b*b - 4*a*c
if (D<0) {
return null
} else if (D==0) {
x1=-1*b / 2*a
return x1
} else if (D>0) {
x1=(-1*b + Math.sqrt(D)) / 2*a
x2=(-1*b - Math.sqrt(D)) / 2*a
return {x1, x2}
}
console.log('-----------------')
}
console.log(solveQuadratic()) // {0}
console.log(solveQuadratic(1, 4, 4)) // {-2}
console.log(solveQuadratic(1, -1, -2)) // {2, -1}
console.log(solveQuadratic(1, 7, 12)) // {-3, -4}
console.log(solveQuadratic(1, 0, -4)) //{2, -2}
console.log(solveQuadratic(1, -1, 0)) //{1, 0}

@ -0,0 +1,34 @@
console.log('Objects Exercises')
/*
Create an empty object called dog
Print the the dog object on the console
Add name, legs, color, age and bark properties for the dog object. The bark property is a method which return woof woof
Get name, legs, color, age and bark value from the dog object
Set new properties the dog object: breed, getDogInfo
*/
const dog = {}
console.log(dog)
dog.name='Dog'
dog.color='Brown'
dog.legs=4
dog.age=5
dog.bark=function () {
console.log('woof woof!')
}
dog.breed='French'
dog.getDogInfo = function () {
console.log('Name: '+dog.name)
console.log('Breed: '+dog.breed)
console.log('Age: '+dog.age)
console.log('Color: '+dog.color)
console.log('Legs: '+dog.legs)
}
dog.getDogInfo()
console.log('Voice!')
dog.bark()

@ -0,0 +1 @@
console.log('Hello, World!')

@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<head>
<title>30DaysOfScript:Inline Script</title>
</head>
<body>
<button onclick="alert('Welcome to 30DaysOfJavaScript!')">Click Me</button>
</body>
</html>

@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<title>30DaysOfScript:Internal Script</title>
<button onclick="alert('Welcome to 30DaysOfJavaScript!');">Click Me</button>
<script>
console.log('Welcome to 30DaysOfJavaScript')
</script>
</head>
<body></body>
</html>

@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<title>30DaysOfJavaScript:External script</title>
<script src="introduction.js"></script>
</head>
<body>
<script src="introduction.js"></script>
</body>
</html>

@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<title>Multiple External Scripts</title>
</head>
<body>
<script src="./hello.js"></script>
<script src="./introduction.js"></script>
</body>
</html>

@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<head>
<title>01-Day. Execise level 1</title>
</head>
<body>
<script src="ex1_cond.js"></script>
</body>
</html>

@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<title>01-Day. Execise level 1</title>
</head>
<body>
<script src="ex1.js"></script>
<script src="countries.js"></script>
<script src="webTechs.js"></script>
<script src="main.js"></script>
<script src="ex2.js"></script>
<script src="ex1_cond.js"></script>
</body>
</html>

@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<head>
<title>01-Day. Execise level 1</title>
</head>
<body>
<script src="ex_func.js"></script>
</body>
</html>

@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<head>
<title>01-Day. Execise level 1</title>
</head>
<body>
<script src="ex_obj.js"></script>
</body>
</html>

@ -0,0 +1 @@
console.log('Welcome to 30DaysOfJavaScript')

@ -0,0 +1,2 @@
console.log(countries)
console.log(webTechs)

@ -0,0 +1,9 @@
const webTechs = [
'HTML',
'CSS',
'JavaScript',
'React',
'Redux',
'Node',
'MongoDB',
]
Loading…
Cancel
Save