From aec1241685ceee765d516e262a1519dbc967c29c Mon Sep 17 00:00:00 2001 From: "Dan.Kapustin" Date: Thu, 1 Jun 2023 10:51:24 +0300 Subject: [PATCH] 01 Day activities --- 01_Day_JavaScript_Refresher/countries.js | 14 +++++ 01_Day_JavaScript_Refresher/ex1.js | 60 +++++++++++++++++++++ 01_Day_JavaScript_Refresher/ex1_cond.js | 40 ++++++++++++++ 01_Day_JavaScript_Refresher/ex2.js | 40 ++++++++++++++ 01_Day_JavaScript_Refresher/ex_func.js | 26 +++++++++ 01_Day_JavaScript_Refresher/ex_obj.js | 34 ++++++++++++ 01_Day_JavaScript_Refresher/hello.js | 1 + 01_Day_JavaScript_Refresher/index.html | 9 ++++ 01_Day_JavaScript_Refresher/index2.html | 11 ++++ 01_Day_JavaScript_Refresher/index3.html | 10 ++++ 01_Day_JavaScript_Refresher/index4.html | 10 ++++ 01_Day_JavaScript_Refresher/indexCond.html | 9 ++++ 01_Day_JavaScript_Refresher/indexEx1.html | 14 +++++ 01_Day_JavaScript_Refresher/indexFunc.html | 9 ++++ 01_Day_JavaScript_Refresher/indexObj.html | 9 ++++ 01_Day_JavaScript_Refresher/introduction.js | 1 + 01_Day_JavaScript_Refresher/main.js | 2 + 01_Day_JavaScript_Refresher/webTechs.js | 9 ++++ 18 files changed, 308 insertions(+) create mode 100644 01_Day_JavaScript_Refresher/countries.js create mode 100644 01_Day_JavaScript_Refresher/ex1.js create mode 100644 01_Day_JavaScript_Refresher/ex1_cond.js create mode 100644 01_Day_JavaScript_Refresher/ex2.js create mode 100644 01_Day_JavaScript_Refresher/ex_func.js create mode 100644 01_Day_JavaScript_Refresher/ex_obj.js create mode 100644 01_Day_JavaScript_Refresher/hello.js create mode 100644 01_Day_JavaScript_Refresher/index.html create mode 100644 01_Day_JavaScript_Refresher/index2.html create mode 100644 01_Day_JavaScript_Refresher/index3.html create mode 100644 01_Day_JavaScript_Refresher/index4.html create mode 100644 01_Day_JavaScript_Refresher/indexCond.html create mode 100644 01_Day_JavaScript_Refresher/indexEx1.html create mode 100644 01_Day_JavaScript_Refresher/indexFunc.html create mode 100644 01_Day_JavaScript_Refresher/indexObj.html create mode 100644 01_Day_JavaScript_Refresher/introduction.js create mode 100644 01_Day_JavaScript_Refresher/main.js create mode 100644 01_Day_JavaScript_Refresher/webTechs.js diff --git a/01_Day_JavaScript_Refresher/countries.js b/01_Day_JavaScript_Refresher/countries.js new file mode 100644 index 0000000..a160521 --- /dev/null +++ b/01_Day_JavaScript_Refresher/countries.js @@ -0,0 +1,14 @@ +const countries = [ + 'Albania', + 'Bolivia', + 'Canada', + 'Denmark', + 'Ethiopia', + 'Finland', + 'Germany', + 'Hungary', + 'Ireland', + 'Japan', + 'Kenya', + ] + diff --git a/01_Day_JavaScript_Refresher/ex1.js b/01_Day_JavaScript_Refresher/ex1.js new file mode 100644 index 0000000..41d9ccb --- /dev/null +++ b/01_Day_JavaScript_Refresher/ex1.js @@ -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 + +*/ + diff --git a/01_Day_JavaScript_Refresher/ex1_cond.js b/01_Day_JavaScript_Refresher/ex1_cond.js new file mode 100644 index 0000000..7202ece --- /dev/null +++ b/01_Day_JavaScript_Refresher/ex1_cond.js @@ -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 +} + diff --git a/01_Day_JavaScript_Refresher/ex2.js b/01_Day_JavaScript_Refresher/ex2.js new file mode 100644 index 0000000..bf4c1b1 --- /dev/null +++ b/01_Day_JavaScript_Refresher/ex2.js @@ -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) \ No newline at end of file diff --git a/01_Day_JavaScript_Refresher/ex_func.js b/01_Day_JavaScript_Refresher/ex_func.js new file mode 100644 index 0000000..c5db788 --- /dev/null +++ b/01_Day_JavaScript_Refresher/ex_func.js @@ -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} diff --git a/01_Day_JavaScript_Refresher/ex_obj.js b/01_Day_JavaScript_Refresher/ex_obj.js new file mode 100644 index 0000000..4c2f496 --- /dev/null +++ b/01_Day_JavaScript_Refresher/ex_obj.js @@ -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() + + + diff --git a/01_Day_JavaScript_Refresher/hello.js b/01_Day_JavaScript_Refresher/hello.js new file mode 100644 index 0000000..8c9e2c0 --- /dev/null +++ b/01_Day_JavaScript_Refresher/hello.js @@ -0,0 +1 @@ +console.log('Hello, World!') \ No newline at end of file diff --git a/01_Day_JavaScript_Refresher/index.html b/01_Day_JavaScript_Refresher/index.html new file mode 100644 index 0000000..0d938bc --- /dev/null +++ b/01_Day_JavaScript_Refresher/index.html @@ -0,0 +1,9 @@ + + + + 30DaysOfScript:Inline Script + + + + + \ No newline at end of file diff --git a/01_Day_JavaScript_Refresher/index2.html b/01_Day_JavaScript_Refresher/index2.html new file mode 100644 index 0000000..aad7a1c --- /dev/null +++ b/01_Day_JavaScript_Refresher/index2.html @@ -0,0 +1,11 @@ + + + + 30DaysOfScript:Internal Script + + + + + \ No newline at end of file diff --git a/01_Day_JavaScript_Refresher/index3.html b/01_Day_JavaScript_Refresher/index3.html new file mode 100644 index 0000000..4e97a18 --- /dev/null +++ b/01_Day_JavaScript_Refresher/index3.html @@ -0,0 +1,10 @@ + + + + 30DaysOfJavaScript:External script + + + + + + \ No newline at end of file diff --git a/01_Day_JavaScript_Refresher/index4.html b/01_Day_JavaScript_Refresher/index4.html new file mode 100644 index 0000000..a0c9023 --- /dev/null +++ b/01_Day_JavaScript_Refresher/index4.html @@ -0,0 +1,10 @@ + + + + Multiple External Scripts + + + + + + \ No newline at end of file diff --git a/01_Day_JavaScript_Refresher/indexCond.html b/01_Day_JavaScript_Refresher/indexCond.html new file mode 100644 index 0000000..a4ffdca --- /dev/null +++ b/01_Day_JavaScript_Refresher/indexCond.html @@ -0,0 +1,9 @@ + + + + 01-Day. Execise level 1 + + + + + \ No newline at end of file diff --git a/01_Day_JavaScript_Refresher/indexEx1.html b/01_Day_JavaScript_Refresher/indexEx1.html new file mode 100644 index 0000000..2efcaca --- /dev/null +++ b/01_Day_JavaScript_Refresher/indexEx1.html @@ -0,0 +1,14 @@ + + + + 01-Day. Execise level 1 + + + + + + + + + + \ No newline at end of file diff --git a/01_Day_JavaScript_Refresher/indexFunc.html b/01_Day_JavaScript_Refresher/indexFunc.html new file mode 100644 index 0000000..e25566e --- /dev/null +++ b/01_Day_JavaScript_Refresher/indexFunc.html @@ -0,0 +1,9 @@ + + + + 01-Day. Execise level 1 + + + + + \ No newline at end of file diff --git a/01_Day_JavaScript_Refresher/indexObj.html b/01_Day_JavaScript_Refresher/indexObj.html new file mode 100644 index 0000000..0b01256 --- /dev/null +++ b/01_Day_JavaScript_Refresher/indexObj.html @@ -0,0 +1,9 @@ + + + + 01-Day. Execise level 1 + + + + + \ No newline at end of file diff --git a/01_Day_JavaScript_Refresher/introduction.js b/01_Day_JavaScript_Refresher/introduction.js new file mode 100644 index 0000000..316199c --- /dev/null +++ b/01_Day_JavaScript_Refresher/introduction.js @@ -0,0 +1 @@ +console.log('Welcome to 30DaysOfJavaScript') \ No newline at end of file diff --git a/01_Day_JavaScript_Refresher/main.js b/01_Day_JavaScript_Refresher/main.js new file mode 100644 index 0000000..c64cd80 --- /dev/null +++ b/01_Day_JavaScript_Refresher/main.js @@ -0,0 +1,2 @@ +console.log(countries) +console.log(webTechs) \ No newline at end of file diff --git a/01_Day_JavaScript_Refresher/webTechs.js b/01_Day_JavaScript_Refresher/webTechs.js new file mode 100644 index 0000000..a057439 --- /dev/null +++ b/01_Day_JavaScript_Refresher/webTechs.js @@ -0,0 +1,9 @@ +const webTechs = [ + 'HTML', + 'CSS', + 'JavaScript', + 'React', + 'Redux', + 'Node', + 'MongoDB', + ] \ No newline at end of file