pull/949/head
Nevzat Atalay 3 years ago
parent 002c34bd01
commit abffa6e71e

@ -9,13 +9,15 @@
//Welcome to 30DaysOfJavaScript //Welcome to 30DaysOfJavaScript
//---------------------------day1_level_1 3.exercise-------------------------\\ //---------------------------day1_level_1 3.exercise-------------------------\\
// Write a multiline comment which says, comments can make code readable, easy to reuse and informative // Write a multiline comment which says, comments can make code readable, easy
// to reuse and informative
/* comments can make code readable, /* comments can make code readable,
easy to reuse and informative */ easy to reuse and informative */
//---------------------------day1_level_1 4.exercise-------------------------\\ //---------------------------day1_level_1 4.exercise-------------------------\\
// Create a variable.js file and declare variables and assign string, boolean, undefined and null data types // Create a variable.js file and declare variables and assign string, boolean,
// undefined and null data types
//variable.js //variable.js
let string = 'nevzat' let string = 'nevzat'
@ -25,7 +27,8 @@ let nulll = null
let any; //undefined let any; //undefined
//---------------------------day1_level_1 5.exercise-------------------------\\ //---------------------------day1_level_1 5.exercise-------------------------\\
// Create datatypes.js file and use the JavaScript typeof operator to check different data types. Check the data type of each variable // Create datatypes.js file and use the JavaScript typeof operator to check
// different data types. Check the data type of each variable
//type.js //type.js
console.log(typeof (string) ) console.log(typeof (string) )
@ -51,7 +54,8 @@ variable3 = true;
variable4 = 25; variable4 = 25;
//---------------------------day1_level_1 8.exercise-------------------------\\ //---------------------------day1_level_1 8.exercise-------------------------\\
// Declare variables to store your first name, last name, marital status, country and age in multiple lines // Declare variables to store your first name, last name, marital status,
// country and age in multiple lines
let firstName = "nevzat" let firstName = "nevzat"
let lastName = "atalay" let lastName = "atalay"
@ -59,12 +63,14 @@ let old = 25
let isMarried = true let isMarried = true
//---------------------------day1_level_1 9.exercise-------------------------\\ //---------------------------day1_level_1 9.exercise-------------------------\\
// Declare variables to store your first name, last name, marital status, country and age in a single line // Declare variables to store your first name, last name, marital status,
// country and age in a single line
let name = "nevzat",surName="atalay",age = 25, married = true let name = "nevzat",surName="atalay",age = 25, married = true
//---------------------------day1_level_1 10.exercise------------------------\\ //---------------------------day1_level_1 10.exercise------------------------\\
// Declare two variables myAge and yourAge and assign them initial values and log to the browser console. // Declare two variables myAge and yourAge and assign them initial values
// and log to the browser console.
let myAge= 25 let myAge= 25
let yourAge = 22 let yourAge = 22

@ -1,6 +1,6 @@
//----------------------------day2_level1 1.exercise-------------------------\\ //----------------------------day2_level1 1.exercise-------------------------\\
// Declare a variable named challenge and assign it to an initial // Declare a variable named challenge and assign it to an initial
value '30 Days Of JavaScript'. //value '30 Days Of JavaScript'.
let challenge = '30 days of javascript' let challenge = '30 days of javascript'
@ -66,7 +66,7 @@ console.log(challenge.split(" "))
//----------------------------day2_level1 11.exercise------------------------\\ //----------------------------day2_level1 11.exercise------------------------\\
// 'Facebook, Google, Microsoft, Apple, IBM, Oracle, Amazon' split the string // 'Facebook, Google, Microsoft, Apple, IBM, Oracle, Amazon' split the string
at the comma and change it to an array. //at the comma and change it to an array.
let companies = 'Facebook, Google, Microsoft, Apple, IBM, Oracle,Amazon' let companies = 'Facebook, Google, Microsoft, Apple, IBM, Oracle,Amazon'
console.log(companies.split(`,`)) console.log(companies.split(`,`))
@ -79,7 +79,7 @@ console.log(challenge.replace("javascript","phyton"))
//----------------------------day2_level1 13.exercise------------------------\\ //----------------------------day2_level1 13.exercise------------------------\\
// What is character at index 15 in '30 Days Of JavaScript' string? // What is character at index 15 in '30 Days Of JavaScript' string?
Use charAt() method. //Use charAt() method.
challenge = "30 days of javascript" challenge = "30 days of javascript"
console.log(challenge.charAt(15)) console.log(challenge.charAt(15))
@ -93,59 +93,59 @@ console.log(challenge.charCodeAt("j"))
//----------------------------day2_level1 15.exercise------------------------\\ //----------------------------day2_level1 15.exercise------------------------\\
// Use indexOf to determine the position of the first occurrence // Use indexOf to determine the position of the first occurrence
of a in 30 Days Of JavaScript //of a in 30 Days Of JavaScript
challenge = "30 days of javascript" challenge = "30 days of javascript"
console.log(challenge.indexOf("a")) console.log(challenge.indexOf("a"))
//----------------------------day2_level1 16.exercise------------------------\\ //----------------------------day2_level1 16.exercise------------------------\\
// Use lastIndexOf to determine the position of the last occurrence of a in // Use lastIndexOf to determine the position of the last occurrence of a in
30 Days Of JavaScript. //30 Days Of JavaScript.
challenge = "30 days of javascript" challenge = "30 days of javascript"
console.log(challenge.lastIndexOf("a")) console.log(challenge.lastIndexOf("a"))
//----------------------------day2_level1 17.exercise------------------------\\ //----------------------------day2_level1 17.exercise------------------------\\
// Use indexOf to find the position of the first occurrence of the word // 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 in the following sentence:'You cannot end a sentence with because
because because is a conjunction' //because because is a conjunction'
let sentence = "You cannot end a sentence with because because is a conjunction." let sentence = "You cannot end a sentence with because because is a conjunction."
console.log(challenge.indexOf("because")) console.log(challenge.indexOf("because"))
//----------------------------day2_level1 18.exercise------------------------\\ //----------------------------day2_level1 18.exercise------------------------\\
// Use lastIndexOf to find the position of the last occurrence of the word // 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 in the following sentence:'You cannot end a sentence with because
because because is a conjunction' //because because is a conjunction'
sentence = "You cannot end a sentence with because because is a conjunction." sentence = "You cannot end a sentence with because because is a conjunction."
console.log(challenge.lastIndexOf("because")) console.log(challenge.lastIndexOf("because"))
//----------------------------day2_level1 19.exercise------------------------\\ //----------------------------day2_level1 19.exercise------------------------\\
// Use search to find the position of the first occurrence of the word because // 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 //in the following sentence:'You cannot end a sentence with because because
because is a conjunction' //because is a conjunction'
sentence = "You cannot end a sentence with because because is a conjunction." sentence = "You cannot end a sentence with because because is a conjunction."
console.log(challenge.search("because")) console.log(challenge.search("because"))
//----------------------------day2_level1 20.exercise------------------------\\ //----------------------------day2_level1 20.exercise------------------------\\
// Use trim() to remove any trailing whitespace at the beginning and the end // Use trim() to remove any trailing whitespace at the beginning and the end
of a string.E.g ' 30 Days Of JavaScript '. //of a string.E.g ' 30 Days Of JavaScript '.
challenge = "30 Days Of JavaScript " challenge = "30 Days Of JavaScript "
console.log(challenge.trim()) console.log(challenge.trim())
//----------------------------day2_level1 21.exercise------------------------\\ //----------------------------day2_level1 21.exercise------------------------\\
// Use startsWith() method with the string 30 Days Of JavaScript and make the // Use startsWith() method with the string 30 Days Of JavaScript and make the
result true // result true
challenge = "30 Days Of JavaScript" challenge = "30 Days Of JavaScript"
console.log(challenge.startsWith(30)) console.log(challenge.startsWith(30))
//----------------------------day2_level1 22.exercise------------------------\\ //----------------------------day2_level1 22.exercise------------------------\\
// Use endsWith() method with the string 30 Days Of JavaScript and make the // Use endsWith() method with the string 30 Days Of JavaScript and make the
result true // result true
challenge = "30 Days Of JavaScript" challenge = "30 Days Of JavaScript"
console.log(challenge.endsWith("JavaScript")) console.log(challenge.endsWith("JavaScript"))
@ -177,15 +177,15 @@ console.log(challenge.repeat(2))
//----------------------------day2_level2 1.exercise-------------------------\\ //----------------------------day2_level2 1.exercise-------------------------\\
// Using console.log() print out the following statement: // Using console.log() print out the following statement:
console.log("The quote 'There is no exercise better for the heart than reaching 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.") down and lifting people up.' by John Holmes teaches us to help one another.`)
//----------------------------day2_level2 2.exercise-------------------------\\ //----------------------------day2_level2 2.exercise-------------------------\\
// Using console.log() print out the following quote by Mother Teresa: // Using console.log() print out the following quote by Mother Teresa:
console.log("Love is not patronizing and charity isn't about pity, it is about 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 love. Charity and love are the same -- with charity you give love, so don't
just give money but reach out your hand instead.") just give money but reach out your hand instead.`)
//----------------------------day2_level2 3.exercise-------------------------\\ //----------------------------day2_level2 3.exercise-------------------------\\
// Using console.log() print out the following quote by Mother Teresa: // Using console.log() print out the following quote by Mother Teresa:
@ -198,7 +198,7 @@ console.log(number1===10)
//----------------------------day2_level2 4.exercise-------------------------\\ //----------------------------day2_level2 4.exercise-------------------------\\
// Check if parseFloat('9.8') is equal to 10 if not make it exactly // Check if parseFloat('9.8') is equal to 10 if not make it exactly
equal with 10. // equal with 10.
let parseNumber =parseFloat(9.8) let parseNumber =parseFloat(9.8)
console.log(number===10) console.log(number===10)
@ -248,11 +248,11 @@ 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 ")
//----------------------------day2_level2 12.exercise------------------------\\ //----------------------------day2_level2 12.exercise------------------------\\
// Use substr to slice out the phrase because because because from the // Use substr to slice out the phrase because because because from the
following sentence:'You cannot end a sentence with because because because is // following sentence:'You cannot end a sentence with because because because is
a conjunction' // a conjunction'
let statement = "You cannot end a sentence with because because because let statement = `You cannot end a sentence with because because because
is a conjunction" is a conjunction`
console.log(statement.replace("because","")) console.log(statement.replace("because",""))
@ -263,32 +263,32 @@ console.log(statement.replace("because",""))
//----------------------------day2_leve3 1.exercise--------------------------\\ //----------------------------day2_leve3 1.exercise--------------------------\\
// 'Love is the best thing in this world. Some found their love and some are // '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. // still looking for their love.' Count the number of word love in this sentence.
let strng ="Love is the best thing in this world. Some found their love and let strng =`Love is the best thing in this world. Some found their love and
some are still looking for their love." some are still looking for their love.`
let count = strng.match(/love/gi)||[].length let count = strng.match(/love/gi)||[].length
console.log(count) console.log(count)
//----------------------------day2_leve3 2.exercise--------------------------\\ //----------------------------day2_leve3 2.exercise--------------------------\\
// Use match() to count the number of all because in the following sentence: // Use match() to count the number of all because in the following sentence:
'You cannot end a sentence with because because because is a conjunction' //'You cannot end a sentence with because because because is a conjunction'
let sentence1 = "You cannot end a sentence with because because because let sentence1 = `You cannot end a sentence with because because because
is a conjunction" is a conjunction`
let count1 = sentence1.match(/because/gi)||[].length let count1 = sentence1.match(/because/gi)||[].length
console.log(count1) console.log(count1)
//----------------------------day2_leve3 3.exercise--------------------------\\ //----------------------------day2_leve3 3.exercise--------------------------\\
// Clean the following text and find the most frequent word // Clean the following text and find the most frequent word
(hint, use replace and regular expressions). // (hint, use replace and regular expressions).
let messySentence = '%I $am@% a %tea@cher%, &and& I lo%#ve %te@a@ching%;. let messySentence = `%I $am@% a %tea@cher%, &and& I lo%#ve %te@a@ching%;.
The@re $is no@th@ing; &as& mo@re rewarding as educa@ting &and& The@re $is no@th@ing; &as& mo@re rewarding as educa@ting &and&
@emp%o@weri@ng peo@ple. ;I found tea@ching m%o@re interesting tha@n @emp%o@weri@ng peo@ple. ;I found tea@ching m%o@re interesting tha@n
any ot#her %jo@bs. %Do@es thi%s mo@tiv#ate yo@u to be a tea@cher!? any ot#her %jo@bs. %Do@es thi%s mo@tiv#ate yo@u to be a tea@cher!?
%Th#is 30#Days&OfJavaScript &is al@so $the $resu@lt of &love& of %Th#is 30#Days&OfJavaScript &is al@so $the $resu@lt of &love& of
tea&ching'; tea&ching`;
let cleanSentence = messySentence.replace(/[^a-zA-Z ]/g, " "); let cleanSentence = messySentence.replace(/[^a-zA-Z ]/g, " ");
let words = cleanSentence.split(' '); let words = cleanSentence.split(' ');
@ -312,11 +312,12 @@ console.log(`Most frequent word is '${maxWord}' with count ${maxCount}`);
//----------------------------day2_leve3 4.exercise--------------------------\\ //----------------------------day2_leve3 4.exercise--------------------------\\
// Calculate the total annual income of the person by extracting the numbers // Calculate the total annual income of the person by extracting the numbers
from the following text. 'He earns 5000 euro from salary per month, 10000 euro //from the following text. 'He earns 5000 euro from salary per month, 10000 euro
annual bonus, 15000 euro online courses per month.' //annual bonus, 15000 euro online courses per month.'
let text =`He earns 5000 euro from salary per month, 10000 euro annual
bonus, 15000 euro online courses per month.`
let text ='He earns 5000 euro from salary per month, 10000 euro annual bonus,
15000 euro online courses per month.'
let pattern =/\d+/g let pattern =/\d+/g
let numbers = text.match(pattern) let numbers = text.match(pattern)

Loading…
Cancel
Save