From 92fd198fe84606fb3278ee2afb4f38503c92c347 Mon Sep 17 00:00:00 2001 From: hoang-tv Date: Wed, 24 Aug 2022 23:35:24 +0700 Subject: [PATCH] feat: add day 2 excersies --- Exercises/day_2/index.html | 13 ++++++++ Exercises/day_2/index_level_2.html | 12 ++++++++ Exercises/day_2/index_level_3.html | 12 ++++++++ Exercises/day_2/script.js | 48 ++++++++++++++++++++++++++++++ Exercises/day_2/script2.js | 28 +++++++++++++++++ Exercises/day_2/script3.js | 45 ++++++++++++++++++++++++++++ Exercises/day_2/variables.js | 1 + 7 files changed, 159 insertions(+) create mode 100644 Exercises/day_2/index.html create mode 100644 Exercises/day_2/index_level_2.html create mode 100644 Exercises/day_2/index_level_3.html create mode 100644 Exercises/day_2/script.js create mode 100644 Exercises/day_2/script2.js create mode 100644 Exercises/day_2/script3.js create mode 100644 Exercises/day_2/variables.js diff --git a/Exercises/day_2/index.html b/Exercises/day_2/index.html new file mode 100644 index 0000000..59748d5 --- /dev/null +++ b/Exercises/day_2/index.html @@ -0,0 +1,13 @@ + + + + + + + Document + + + + + + \ No newline at end of file diff --git a/Exercises/day_2/index_level_2.html b/Exercises/day_2/index_level_2.html new file mode 100644 index 0000000..3e591ce --- /dev/null +++ b/Exercises/day_2/index_level_2.html @@ -0,0 +1,12 @@ + + + + + + + Document + + + + + \ No newline at end of file diff --git a/Exercises/day_2/index_level_3.html b/Exercises/day_2/index_level_3.html new file mode 100644 index 0000000..48f3d99 --- /dev/null +++ b/Exercises/day_2/index_level_3.html @@ -0,0 +1,12 @@ + + + + + + + Document + + + + + \ No newline at end of file diff --git a/Exercises/day_2/script.js b/Exercises/day_2/script.js new file mode 100644 index 0000000..31aa396 --- /dev/null +++ b/Exercises/day_2/script.js @@ -0,0 +1,48 @@ +console.log(chanllenge, `length is ${chanllenge.length}`); + +chanllenge_was_lowered = chanllenge.toLocaleLowerCase(); +console.log(`lower case of chanllenge is ${chanllenge_was_lowered}`); + +chanllenge_was_uppered = chanllenge.toUpperCase(); +console.log(`upper case of chanllenge is ${chanllenge_was_uppered}`); + +first_str_of_challenge = chanllenge.substring(0, 1); +console.log(`first charactor of chanllenge is ${chanllenge_was_uppered}`); + +console.log(`Slice out the phrase Days Of JavaScript from 30 Days Of JavaScript: ${chanllenge.replace('Days Of JavaScript','')}`) + +console.log(`Check if the string contains a word Script using includes() method: ${chanllenge.includes('Script')}`) + +console.log(`Split the string into an array using split() method: ${chanllenge.split('')}`) + +console.log(`Split the string 30 Days Of JavaScript at the space using split() method: ${chanllenge.split(' ')}`) + +console.log(`'Facebook, Google, Microsoft, Apple, IBM, Oracle, Amazon' split the string at the comma and change it to an array: ${'Facebook, Google, Microsoft, Apple, IBM, Oracle, Amazon'.split(',')}`) + +console.log(`Change 30 Days Of JavaScript to 30 Days Of Python using replace() method: ${chanllenge.replace('JavaScript', 'Python')}`) + +console.log(`What is character at index 15 in '30 Days Of JavaScript' string? Use charAt() method: ${chanllenge.charAt(15)}`) + +console.log(`What is the character code of J in '30 Days Of JavaScript' string using charCodeAt(): ${chanllenge.charCodeAt(chanllenge.indexOf('J'))}`) + +console.log(`Use indexOf to determine the position of the first occurrence of a in 30 Days Of JavaScript: ${chanllenge.indexOf('a')}`) + +console.log(`Use lastIndexOf to determine the position of the last occurrence of a in 30 Days Of JavaScriptL: ${chanllenge.lastIndexOf('a')}`) + +console.log(`Use indexOf to find the position of the first occurrence of the word because in the following sentence: ${'You cannot end a sentence with because because because is a conjunction'.indexOf('because')}`) + +console.log(`Use lastIndexOf to find the position of the last occurrence of the word because in the following sentence: ${'You cannot end a sentence with because because because is a conjunction'.lastIndexOf('because')}`) + +console.log(`Use search to find the position of the first occurrence of the word because in the following sentence: ${'You cannot end a sentence with because because because is a conjunction'.search('because')}`) + +console.log(`Use trim() to remove any trailing whitespace at the beginning and the end of a string.E.g: ${' 30 Days Of JavaScript '.trim()}`) + +console.log(`Use startsWith() method with the string 30 Days Of JavaScript and make the result true ${chanllenge.startsWith('30')}`) + +console.log(`Use endsWith() method with the string 30 Days Of JavaScript and make the result true: ${chanllenge.endsWith('JavaScript')}`) + +console.log(`Use match() method to find all the a’s in 30 Days Of JavaScript: ${chanllenge.match("a’s")}`) + +console.log(`Use concat() and merge '30 Days of' and 'JavaScript' to a single string, '30 Days Of JavaScript': ${'30 Days of'.concat('JavaScript')}`) + +console.log(`Use repeat() method to print 30 Days Of JavaScript 2 times: ${chanllenge.repeat(2)}`) \ No newline at end of file diff --git a/Exercises/day_2/script2.js b/Exercises/day_2/script2.js new file mode 100644 index 0000000..cdaced8 --- /dev/null +++ b/Exercises/day_2/script2.js @@ -0,0 +1,28 @@ +console.log("The quote 'There is no exercise better for the heart \ +than reaching down and lifting people up.' by John Holmes teaches us to help one another.") + +console.log("Love is not patronizing and charity isn't about pity, it is about love. \ +Charity and love are the same -- with charity you give love, \ +so don't just give money but reach out your hand instead.") + +console.log("Check if typeof '10' is exactly equal to 10. If not make it exactly equal", parseInt('10') == 10) + +console.log("Check if parseFloat('9.8') is equal to 10 if not make it exactly equal with 10:", Math.ceil(parseFloat('9.8')) == 10) + +console.log("Check if 'on' is found in both python and jargon", "python".includes("on") && "jargon".includes("on")) + +sentence = "I hope this course is not full of jargon. Check if jargon is in the sentence: " +console.log(sentence, sentence.includes("jargon")) + +console.log("Generate a random number between 0 and 100 inclusively", Math.floor(Math.random()*101)) + +console.log("Generate a random number between 50 and 100 inclusively.", Math.floor(Math.random()*51) + 50) + +console.log("Generate a random number between 0 and 255 inclusively.", Math.floor(Math.random()*250)) + +console.log("Access the 'JavaScript' string characters using a random number.", "Javascript"[Math.floor(Math.random()*"Javascript".length)]) + +console.log("1 1 1 1 1\n2 1 2 4 8\n3 1 3 9 27\n4 1 4 16 64\n5 1 5 25 125\n") + +let str = 'You cannot end a sentence with because because because is a conjunction' +console.log("Use substr to slice out the phrase because because because from the following sentence:'You cannot end a sentence with because because because is a conjunction'", str.substr(str.indexOf("because because because"), "because because because".length)) \ No newline at end of file diff --git a/Exercises/day_2/script3.js b/Exercises/day_2/script3.js new file mode 100644 index 0000000..8b1fced --- /dev/null +++ b/Exercises/day_2/script3.js @@ -0,0 +1,45 @@ +//Love is the best thing in this world. Some found their love and some are still looking for their love.' Count the number of word love in this sentence. + +let str_1 = 'Love is the best thing in this world. Some found their love and some are still looking for their love.' + +function number_of_word(str, word){ + str = str.toLowerCase(); + word = word.toLowerCase(); + let res = 0; + while (str.includes(word)) { + res++; + str = str.replace(word, ""); + } + return res; +} + +function use_match(str, word){ + str = str.toLowerCase(); + word = word.toLowerCase(); + let res = 0; + while (str.match(word)) { + res++; + str = str.replace(word, ""); + } + return res; + +} + +console.log(number_of_word(str_1, "love")) +console.log(use_match(str_1, "love")) + +let income_text = 'He earns 5000 euro from salary per month, 10000 euro annual bonus, 15000 euro online courses per month.' + +let income_arr = income_text.split(" ") + +let income = 0 + +income_arr.forEach(count_money) + +function count_money(value) +{ + if(parseFloat(value) == value) + income += parseFloat(value) +} + +console.log(income) \ No newline at end of file diff --git a/Exercises/day_2/variables.js b/Exercises/day_2/variables.js new file mode 100644 index 0000000..3267766 --- /dev/null +++ b/Exercises/day_2/variables.js @@ -0,0 +1 @@ +let chanllenge = '30 Days Of JavaScript' \ No newline at end of file