Merge pull request #2 from hoangdev72/develop

feat: add day 2 excersies
pull/593/head
hoangdev72 3 years ago committed by GitHub
commit d6bda7d7a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script src="variables.js"></script>
<script src="script.js"></script>
</body>
</html>

@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script src="script2.js"></script>
</body>
</html>

@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script src="script3.js"></script>
</body>
</html>

@ -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 as in 30 Days Of JavaScript: ${chanllenge.match("as")}`)
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)}`)

@ -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))

@ -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)

@ -0,0 +1 @@
let chanllenge = '30 Days Of JavaScript'
Loading…
Cancel
Save