minor changes

pull/949/head
Nevzat Atalay 2 years ago
parent bcdfea5fd3
commit 74ef9b5d83

@ -0,0 +1,121 @@
# Day 1 - Introduction
## [< Home >](../README.md) | [Day 2 >>](./02_day_datatype.md)
### [Exercise Level 1](#exercise-level-1)
### Exercise Level 1
1. Write a single line comment which says, _comments can make code readable_
2. Write another single comment which says, _Welcome to 30DaysOfJavaScript_
3. Write a multiline comment which says, _comments can make code readable, easy to reuse_
_and informative_
4. Create a variable.js file and declare variables and assign string, boolean, undefined and null data types
5. Create datatypes.js file and use the JavaScript **_typeof_** operator to check different data types. Check the data type of each variable
6. Declare four variables without assigning values
7. Declare four variables with assigned values
8. Declare variables to store your first name, last name, marital status, country and age in multiple lines
9. Declare variables to store your first name, last name, marital status, country and age in a single line
10. Declare two variables _myAge_ and _yourAge_ and assign them initial values and log to the browser console.
```sh
I am 25 years old.
You are 30 years old.
```
### Exercise Level 1
1. Write a single line comment which says, comments can make code readable
```js
// comments can make code readable
```
2. Write another single comment which says, Welcome to 30DaysOfJavaScript
```js
//Welcome to 30DaysOfJavaScript
```
3. Write a multiline comment which says, comments can make code readable, easy to reuse and informative
```js
/* comments can make code readable,
easy to reuse and informative */
```
4. Create a variable.js file and declare variables and assign string, boolean, undefined and null data types
```js
//variable.js
let string = 'nevzat'
let number = 25
let boolean = true
let nulll = null
let any; //undefined
```
5.Create datatypes.js file and use the JavaScript typeof operator to check different data types. Check the data type of each variable
```js
//variable.js
let string = 'nevzat'
let number = 25
let boolean = true
let nulll = null
let any;
console.log(typeof (string) ) //String
console.log(typeof (number)) //Number
console.log(typeof (boolean)) //Boolean
console.log(typeof (nulll)) //Object
console.log(typeof (any)) //Undefined
```
6. Declare four variables without assigning values
```js
let variable1;
let variable2;
var variable3;
let variable4;
```
7. Declare four variables with assigned values
```js
variable1 = "nevzat"
variable2 = "ATALAY"
variable3 = true;
variable4 = 25;
```
8. Declare variables to store your first name, last name, marital status, country and age in multiple lines
```js
let firstName = "nevzat"
let lastName = "atalay"
let old = 25
let isMarried = true
```
9. Declare variables to store your first name, last name, marital status, country and age in a single line
```js
let name = "nevzat",surName="atalay",age = 25, married = true
```
10. Declare two variables myAge and yourAge and assign them initial values and log to the browser console.
```js
let myAge= 25
let yourAge = 22
console.log("I am " + " " + myAge + " " + "years old.") // I am 25 years old.
console.log("You are" + " " + yourAge + " " + "years old.") // You are 22 years old.
```
## [< Home >](../README.md) | [Day 2 >>](./02_day_datatype.md)

@ -0,0 +1,460 @@
# Exercise Day 2 - DataType
## [Home](../README.md) | [<< Day 1](./01_day_introdiction.md) | [Day 3 >>](./03_day_operators.md)
### [Exercise:Level 1](#exercise-level-1)
1. Declare a variable named challenge and assign it to an initial value **'30 Days Of JavaScript'**.
2. Print the string on the browser console using __console.log()__
3. Print the __length__ of the string on the browser console using _console.log()_
4. Change all the string characters to capital letters using __toUpperCase()__ method
5. Change all the string characters to lowercase letters using __toLowerCase()__ method
6. Cut (slice) out the first word of the string using __substr()__ or __substring()__ method
7. Slice out the phrase *Days Of JavaScript* from *30 Days Of JavaScript*.
8. Check if the string contains a word __Script__ using __includes()__ method
9. Split the __string__ into an __array__ using __split()__ method
10. Split the string 30 Days Of JavaScript at the space using __split()__ method
11. 'Facebook, Google, Microsoft, Apple, IBM, Oracle, Amazon' __split__ the string at the comma and change it to an array.
12. Change 30 Days Of JavaScript to 30 Days Of Python using __replace()__ method.
13. What is character at index 15 in '30 Days Of JavaScript' string? Use __charAt()__ method.
14. What is the character code of J in '30 Days Of JavaScript' string using __charCodeAt()__
15. Use __indexOf__ to determine the position of the first occurrence of __a__ in 30 Days Of JavaScript
16. Use __lastIndexOf__ to determine the position of the last occurrence of __a__ in 30 Days Of JavaScript.
17. 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'__
18. 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'__
19. 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'__
20. Use __trim()__ to remove any trailing whitespace at the beginning and the end of a string.E.g ' 30 Days Of JavaScript '.
21. Use __startsWith()__ method with the string *30 Days Of JavaScript* and make the result true
22. Use __endsWith()__ method with the string *30 Days Of JavaScript* and make the result true
23. Use __match()__ method to find all the __a__s in 30 Days Of JavaScript
24. Use __concat()__ and merge '30 Days of' and 'JavaScript' to a single string, '30 Days Of JavaScript'
25. Use __repeat()__ method to print 30 Days Of JavaScript 2 times
### [Exercise:Level 2](#exercise-level-2)
1. Using console.log() print out the following statement:
```sh
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.
```
2. Using console.log() print out the following quote by Mother Teresa:
```sh
"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."
```
3. Check if typeof '10' is exactly equal to 10. If not make it exactly equal.
4. Check if parseFloat('9.8') is equal to 10 if not make it exactly equal with 10.
5. Check if 'on' is found in both python and jargon
6. _I hope this course is not full of jargon_. Check if _jargon_ is in the sentence.
7. Generate a random number between 0 and 100 inclusively.
8. Generate a random number between 50 and 100 inclusively.
9. Generate a random number between 0 and 255 inclusively.
10. Access the 'JavaScript' string characters using a random number.
11. Use console.log() and escape characters to print the following pattern.
```js
1 1 1 1 1
2 1 2 4 8
3 1 3 9 27
4 1 4 16 64
5 1 5 25 125
```
12. 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'__
### [Exercise:Level 3](#exercise-level-3)
1. '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.
2. 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'__
3. Clean the following text and find the most frequent word (hint, use replace and regular expressions).
```js
const sentence = '%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& @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!? %Th#is 30#Days&OfJavaScript &is al@so $the $resu@lt of &love& of tea&ching'
```
4. 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 annual bonus, 15000 euro online courses per month.'
## Exercise Level 1
1. Declare a variable named challenge and assign it to an initial value '30 Days Of JavaScript'.
```js
let challenge = '30 days of javascript'
```
2. Print the string on the browser console using console.log()
```js
challenge = '30 days of javascript'
console.log(challenge)
```
3. Print the length of the string on the browser console using console.log()
```js
challenge = '30 days of javascript'
console.log(challenge.length)
```
4. Change all the string characters to capital letters using toUpperCase()
method
```js
challenge = '30 days of javascript'
console.log(challenge.toUpperCase())
```
5. Change all the string characters to lowercase letters using toLowerCase() method
```js
challenge = '30 days of javascript'
console.log(challenge.toLowerCase())
```
6. Cut (slice) out the first word of the string using substr() or substring() method
```js
challenge = '30 days of javascript'
console.log(challenge.substring(3, 5))
```
7. Slice out the phrase Days Of JavaScript from 30 Days Of JavaScript.
```js
challenge = '30 days of javascript'
let newChallenge = challenge.slice(3,10)
console.log(newChallenge)
```
8. Check if the string contains a word Script using includes() method
```js
challenge = '30 days of javascript'
console.log(challenge.includes('script'))
```
9. Split the string into an array using split() method
```js
challenge = '30 days of javascript'
console.log(challenge.split(""))
```
10. Split the string 30 Days Of JavaScript at the space using split() method
```js
challenge = '30 days of javascript'
console.log(challenge.split(" "))
```
11. 'Facebook, Google, Microsoft, Apple, IBM, Oracle, Amazon' split the string at the comma and change it to an array.
```js
let companies = 'Facebook, Google, Microsoft, Apple, IBM, Oracle,Amazon'
console.log(companies.split(`,`))
```
12. Change 30 Days Of JavaScript to 30 Days Of Python using replace() method.
```js
challenge = "30 days of javascript"
console.log(challenge.replace("javascript","phyton"))
```
13. What is character at index 15 in '30 Days Of JavaScript' string? Use charAt() method.
```js
challenge = "30 days of javascript"
console.log(challenge.charAt(15))
```
14. What is the character code of J in '30 Days Of JavaScript' string using
charCodeAt()
```js
challenge = "30 days of javascript"
console.log(challenge.charCodeAt("j"))
```
15. Use indexOf to determine the position of the first occurrence of a in 30 Days Of JavaScript
```js
challenge = "30 days of javascript"
console.log(challenge.indexOf("a"))
```
16. Use lastIndexOf to determine the position of the last occurrence of a in 30 Days Of JavaScript.
```js
challenge = "30 days of javascript"
console.log(challenge.lastIndexOf("a"))
```
17. 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'
```js
let sentence = "You cannot end a sentence with because because is a conjunction."
console.log(challenge.indexOf("because"))
```
18. 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'
```js
sentence = "You cannot end a sentence with because because is a conjunction."
console.log(challenge.lastIndexOf("because"))
```
19. 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'
```js
sentence = "You cannot end a sentence with because because is a conjunction."
console.log(challenge.search("because"))
```
20. Use trim() to remove any trailing whitespace at the beginning and the end of a string.E.g ' 30 Days Of JavaScript '.
```js
challenge = "30 Days Of JavaScript "
console.log(challenge.trim())
```
21. Use startsWith() method with the string 30 Days Of JavaScript and make the result true
```js
challenge = "30 Days Of JavaScript"
console.log(challenge.startsWith(30))
```
22. Use endsWith() method with the string 30 Days Of JavaScript and make the result true
```js
challenge = "30 Days Of JavaScript"
console.log(challenge.endsWith("JavaScript"))
```
23. Use match() method to find all the as in 30 Days Of JavaScript
```js
challenge = "30 Days Of JavaScript"
console.log(challenge.match("a"))
```
24. Use concat() and merge '30 Days of' and 'JavaScript' to a single string,
'30 Days Of JavaScript'
```js
let stringOne = "30 Days Of "
let stringTwo = "JavaScript"
console.log(stringOne.concat(stringTwo))
```
25. Use repeat() method to print 30 Days Of JavaScript 2 times
```js
challenge = "30 Days Of JavaScript"
console.log(challenge.repeat(2))
```
## Exercise Level 2
1. Using console.log() print out the following statement:
```js
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.`)
```
2. Using console.log() print out the following quote by Mother Teresa: 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.`)
```
3. Using console.log() print out the following quote by Mother Teresa:
```js
let number = "10"
console.log(number===10)
let number1 = 10
console.log(number1===10)
```
4. Check if parseFloat('9.8') is equal to 10 if not make it exactly equal with 10.
```js
let parseNumber =parseFloat(9.8)
console.log(number===10)
let ceilNumber = Math.ceil(parseFloat(9.8))
console.log(number1===10)
```
5. Check if 'on' is found in both python and jargon
```js
let string = "phyton"
let string1 ="jargon"
console.log(string.includes("on") && string1.includes("on"))
```
6. I hope this course is not full of jargon. Check if jargon is in the sentence.
```js
let str = "I hope this course is not full of jargon."
console.log(str.includes("jargon"))
```
7. Generate a random number between 0 and 100 inclusively.
```js
console.log(parseInt(Math.random()*101))
```
8. Generate a random number between 50 and 100 inclusively.
```js
console.log(parseInt(Math.random()*51+50))
```
9. Generate a random number between 0 and 255 inclusively.
```js
console.log(parseInt(Math.random()*255))
```
10. Access the 'JavaScript' string characters using a random number.
```js
let word="javasicript"
let n =parseInt(Math.random()*11)
console.log(word[n])
```
11. Use console.log() and escape characters to print the following pattern.
```
1 1 1 1 1
2 1 2 4 8
3 1 3 9 27
4 1 4 16 64
5 1 5 25 125
```
```js
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 ")
```
12. 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'
```js
let statement = `You cannot end a sentence with because because because
is a conjunction`
console.log(statement.replace("because",""))
```
## Exercise Level 3
1. '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.
```js
let strng =`Love is the best thing in this world. Some found their love and
some are still looking for their love.`
let count = strng.match(/love/gi)||[].length
console.log(count)
```
2. 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'
```js
let sentence1 = `You cannot end a sentence with because because because
is a conjunction`
let count1 = sentence1.match(/because/gi)||[].length
console.log(count1)
```
3. Clean the following text and find the most frequent word (hint, use replace and regular expressions).
```
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&
@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!?
%Th#is 30#Days&OfJavaScript &is al@so $the $resu@lt of &love& of
tea&ching`;
```
```js
let cleanSentence = messySentence.replace(/[^a-zA-Z ]/g, " ");
let words = cleanSentence.split(' ');
let wordCounts = {};
for(let i = 0; i < words.length; i++) {
if(words[i] !== '') {
wordCounts[words[i]] = (wordCounts[words[i]] || 0) + 1;
}
}
let maxWord = '';
let maxCount = 0;
for(let word in wordCounts) {
if(wordCounts[word] > maxCount) {
maxCount = wordCounts[word];
maxWord = word;
}
}
console.log(`Most frequent word is '${maxWord}' with count ${maxCount}`);
```
4. 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 annual bonus, 15000 euro online courses per month.'
```js
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 numbers = text.match(pattern)
numbers = numbers.map(Number);
let montlySalary = numbers[0]
let bonus = numbers[1]
let montlyCourses = numbers[2]
console.log(`Annual income is ${montlySalary*12 +
bonus + montlyCourses *12} euro `)
```
## [Home](../README.md) | [<< Day 1](./01_day_introdiction.md) | [Day 3 >>](./03_day_operators.md)

@ -0,0 +1,497 @@
# Day 3 - Operators
## [Home](../README.md) | [<< Day 2](./02_day_datatype.md) | [Day 4 >>](./04_day_conditional.md)
### [Exercise:Level 1](#exercise-level-1)
1. Declare firstName, lastName, country, city, age, isMarried, year variable and assign value to it and use the typeof operator to check different data types.
2. Check if type of '10' is equal to 10
3. Check if parseInt('9.8') is equal to 10
4. Boolean value is either true or false.
1. Write three JavaScript statement which provide truthy value.
2. Write three JavaScript statement which provide falsy value.
5. Figure out the result of the following comparison expression first without using console.log(). After you decide the result confirm it using console.log()
1. 4 > 3
2. 4 >= 3
3. 4 < 3
4. 4 <= 3
5. 4 == 4
6. 4 === 4
7. 4 != 4
8. 4 !== 4
9. 4 != '4'
10. 4 == '4'
11. 4 === '4'
12. Find the length of python and jargon and make a falsy comparison statement.
6. Figure out the result of the following expressions first without using console.log(). After you decide the result confirm it by using console.log()
1. 4 > 3 && 10 < 12
2. 4 > 3 && 10 > 12
3. 4 > 3 || 10 < 12
4. 4 > 3 || 10 > 12
5. !(4 > 3)
6. !(4 < 3)
7. !(false)
8. !(4 > 3 && 10 < 12)
9. !(4 > 3 && 10 > 12)
10. !(4 === '4')
11. There is no 'on' in both dragon and python
7. Use the Date object to do the following activities
1. What is the year today?
2. What is the month today as a number?
3. What is the date today?
4. What is the day today as a number?
5. What is the hours now?
6. What is the minutes now?
7. Find out the numbers of seconds elapsed from January 1, 1970 to now.
### [Exercise:Level 2](#exercise-level-2)
1. Write a script that prompt the user to enter base and height of the triangle and calculate an area of a triangle (area = 0.5 x b x h).
```sh
Enter base: 20
Enter height: 10
The area of the triangle is 100
```
1. Write a script that prompt the user to enter side a, side b, and side c of the triangle and and calculate the perimeter of triangle (perimeter = a + b + c)
```sh
Enter side a: 5
Enter side b: 4
Enter side c: 3
The perimeter of the triangle is 12
```
1. Get length and width using prompt and calculate an area of rectangle (area = length x width and the perimeter of rectangle (perimeter = 2 x (length + width))
1. Get radius using prompt and calculate the area of a circle (area = pi x r x r) and circumference of a circle(c = 2 x pi x r) where pi = 3.14.
1. Calculate the slope, x-intercept and y-intercept of y = 2x -2
1. Slope is m = (y<sub>2</sub>-y<sub>1</sub>)/(x<sub>2</sub>-x<sub>1</sub>). Find the slope between point (2, 2) and point(6,10)
1. Compare the slope of above two questions.
1. Calculate the value of y (y = x<sup>2</sup> + 6x + 9). Try to use different x values and figure out at what x value y is 0.
1. Writ a script that prompt a user to enter hours and rate per hour. Calculate pay of the person?
```sh
Enter hours: 40
Enter rate per hour: 28
Your weekly earning is 1120
```
1. If the length of your name is greater than 7 say, your name is long else say your name is short.
1. Compare your first name length and your family name length and you should get this output.
```js
let firstName = 'Asabeneh'
let lastName = 'Yetayeh'
```
```sh
Your first name, Asabeneh is longer than your family name, Yetayeh
```
1. Declare two variables _myAge_ and _yourAge_ and assign them initial values and myAge and yourAge.
```js
let myAge = 250
let yourAge = 25
```
```sh
I am 225 years older than you.
```
1. Using prompt get the year the user was born and if the user is 18 or above allow the user to drive if not tell the user to wait a certain amount of years.
```sh
Enter birth year: 1995
You are 25. You are old enough to drive
Enter birth year: 2005
You are 15. You will be allowed to drive after 3 years.
```
1. Write a script that prompt the user to enter number of years. Calculate the number of seconds a person can live. Assume some one lives just hundred years
```sh
Enter number of years you live: 100
You lived 3153600000 seconds.
```
1. Create a human readable time format using the Date time object
1. YYYY-MM-DD HH:mm
2. DD-MM-YYYY HH:mm
3. DD/MM/YYYY HH:mm
### [Exercise:Level 3](#exercise-level-3)
1. Create a human readable time format using the Date time object. The hour and the minute should be all the time two digits(7 hours should be 07 and 5 minutes should be 05 )
1. YYY-MM-DD HH:mm eg. 20120-01-02 07:05
## Exercise Level 1
1. Declare firstName, lastName, country, city, age, isMarried, year variable and assign value to it and use the typeof operator to check different data types.
```js
let name = "nevzat"
let lastName = "atalay"
let country = "turkey"
let city = "bitlis"
let age = 25
let isMarried = true
console.log(typeof(name),typeof(lastName),typeof(country),typeof(city),typeof(age),typeof(isMarried))
```
2. Check if type of '10' is equal to 10
```js
let number ="10"
console.log(number==10)
```
3. Check if parseInt('9.8') is equal to 10
```js
let number = parseInt(9.8)
console.log(number==10)
```
4. Boolean value is either true or false.
- Write three JavaScript statement which provide truthy value.
- Write three JavaScript statement which provide falsy value.
```js
console.log(!!"merhaba")
console.log(!!1)
console.log(!![])
console.log(!!"")
console.log(!!0)
console.log(!!null)
```
5. Figure out the result of the following comparison expression first without using console.log(). After you decide the result confirm it using console.log()
- 4 > 3
- 4 >= 3
- 4 < 3
- 4 <= 3
- 4 == 4
- 4 === 4
- 4 != 4
- 4 !== 4
- 4 != '4'
- 4 == '4'
- 4 === '4'
- Find the length of python and jargon and make a falsy comparison statement.
```js
const arr = [
4 > 3,
4 >= 3,
4 < 3,
4 <= 3,
4 == 4,
4 === 4,
4 != 4,
4 !== 4,
4 != '4',
4 == '4',
4 === '4',
]
console.log(arr)
let string = "phyton", string1 = "jargon"
console.log(string.length >= string1.length )
```
6. Figure out the result of the following expressions first without using console.log(). After you decide the result confirm it by using console.log()
- 4 > 3 && 10 < 12
- 4 > 3 && 10 > 12
- 4 > 3 || 10 < 12
- 4 > 3 || 10 > 12
- !(4 > 3)
- !(4 < 3)
- !(false)
- !(4 > 3 && 10 < 12)
- !(4 > 3 && 10 > 12)
- !(4 === '4')
- There is no 'on' in both dragon and python
```js
const arr = [
4 > 3 && 10 < 12,
4 > 3 && 10 > 12,
4 > 3 || 10 < 12,
4 > 3 || 10 > 12,
!(4 > 3),
!(4 < 3),
!(false),
!(4 > 3 && 10 < 12),
!(4 > 3 && 10 > 12),
!(4 === '4')]
console.log(arr)
let string = "phyton", string1 = "jargon"
console.log(string.includes("on") && string1.includes("on"))
```
7. Use the Date object to do the following activities
- What is the year today?
- What is the month today as a number?
- What is the date today?
- What is the day today as a number?
- What is the hours now?
- What is the minutes now?
- Find out the numbers of seconds elapsed from January 1, 1970 to now.
```js
let now = new Date()
console.log(now.getFullYear())
console.log(now.getMonth()+1)
console.log(now.getDay())
console.log(now.getHours())
console.log(now.getMinutes())
console.log(now.getTime())
```
## Exercise Level 2
1. Write a script that prompt the user to enter base and height of the triangle and calculate an area of a triangle (area = 0.5 x b x h).
```
Enter base: 20
Enter height: 10
The area of the triangle is 100
```
```js
let width =Number(prompt("üçgenin genişligini giriniz"))
let height =Number(prompt("üçgenin yğksekliğini giriniz"))
let area = width*height / 2
console.log(area)
```
2. Write a script that prompt the user to enter side a, side b, and side c of the triangle and and calculate the perimeter of triangle (perimeter = a + b + c)
```
Enter side a: 5
Enter side b: 4
Enter side c: 3
The perimeter of the triangle is 12
```
```js
let width =Number(prompt("üçgenin a kenarını giriniz"))
let height =Number(prompt("üçgenin yüksekliğini giriniz"))
let widthb = Number(prompt("üçgenin b kenarını giriniz"))
let perimeter = width+height+widthb
console.log(perimeter)
```
3. Get length and width using prompt and calculate an area of rectangle (area = length x width and the perimeter of rectangle (perimeter = 2 x (length + width))
```js
let width = Number(prompt("dikdörtgenin genişliğini giriniz"))
let height = Number(prompt("dikdörtgenin yüksekliğini giriniz"))
let perimeter = 2*(width+height)
console.log(perimeter)
```
4. Get radius using prompt and calculate the area of a circle (area = pi x r x r) and circumference of a circle(c = 2 x pi x r) where pi = 3.14.
```js
let r = 5
let area = Math.PI * r**2
console.log(area)
```
5. Calculate the slope, x-intercept and y-intercept of y = 2x -2
```js
let slope = 2 //x in katsayısı egimi verir
let x_intercept = 1
let y_intercept = 2
console.log(`denklemin eğimi ${slope}, x in kesme noktası ${x_intercept}, y nin kesme noktası ${y_intercept} dir`)
```
6. Slope is m = (y2-y1)/(x2-x1). Find the slope between point (2, 2) and point(6,10)
```js
let x1 =2 , x2 = 6
let y1 = 2 ,y2 =10
let slope =( y2 - y1 ) / (x2 - x1)
console.log(slope)
```
7. Compare the slope of above two questions.
```js
let slope1 = 2
let slope2 = 2
console.log(slope1==slope2)
```
8. Calculate the value of y (y = x2 + 6x + 9). Try to use different x values and figure out at what x value y is 0.
```js
let y = (x + 3)**2
let x = [-3,-2,-1,0,1,2,3]
y nin 0 debuggeri için x -3tür
```
9. Writ a script that prompt a user to enter hours and rate per hour. Calculate pay of the person?
```
Enter hours: 40
Enter rate per hour: 28
Your weekly earning is 1120
```
```js
let hours = Number(prompt("günde kaç saat çalışıyorsunuz"))
let workingWage = Number(prompt("saatlik çalışma ücretinizi giriniz"))
let wage = hours*workingWage*30
console.log(`maaşınız ${wage} tl dir`)
```
10. If the length of your name is greater than 7 say, your name is long else say your name is short.
```js
let myName = "nevzat"
if(myName.length > 7){
console.log("adınız uzundur")
}
else{
console.log("adınız kıssadır")
}
```
11. Compare your first name length and your family name length and you should get this output.
```
let firstName = 'Asabeneh'
let lastName = 'Yetayeh'
```
```
Your first name, Asabeneh is longer than your family name, Yetayeh
```
```js
let myName = "nevzat"
let myLastName = "talay"
if(myName.length > myLastName.length){
console.log(`adınız nevzat soyadınız atalaydan daha uzundur`)
}
else{
console.log("soyadınız atalay adınız nevzattan daha uzundur")
}
```
12. Declare two variables myAge and yourAge and assign them initial values and myAge and yourAge.
```
let myAge = 250
let yourAge = 25
```
```
I am 225 years older than you.
```
```js
let myAge =25
let yourAge =18
let message = myAge - yourAge > yourAge - myAge ? "ben senden büyüğüm" : "sen benden büyüksün"
console.log(message)
```
13. Using prompt get the year the user was born and if the user is 18 or above allow the user to drive if not tell the user to wait a certain amount of years.
```
Enter birth year: 1995
You are 25. You are old enough to drive
Enter birth year: 2005
You are 15. You will be allowed to drive after 3 years.
```
```js
let birtYear = Number(prompt("doğum yılınızı giriniz"))
let now = new Date()
let year = now.getFullYear()
let age = year - birtYear
if(age >=18){
console.log("ehliyet sınavına başvuru yapabilirsiniz")
}
else{
console.log(`ehliyet sınavına başvuru yapabilmeniz için ${18-age} yıl beklemeniz gerekmektedir`)
}
```
14. Write a script that prompt the user to enter number of years. Calculate the number of seconds a person can live. Assume some one lives just hundred years
```
Enter number of years you live: 100
You lived 3153600000 seconds.
```
```js
let age = Number(prompt("kaç yaşındasınız"))
let lastSecond = age*365*24*60*60
let remainingSeconds = (100*365*24*60*60) - (lastSecond)
console.log(`en fazla ${remainingSeconds} saniye ömrÜn kaldı WAKW UP`)
```
15. Create a human readable time format using the Date time object
```
- YYYY-MM-DD HH:mm
- DD-MM-YYYY HH:mm
- DD/MM/YYYY HH:mm
```
```js
let now = new Date()
let year = now.getFullYear()
let mount = now.getMonth()
let day = now.getDay()
let hours = now.getHours()
let minuts = now.getMinutes()
console.log(`${year}-${mount}-${day} ${hours} : ${minuts}`)
console.log(`${day}-${mount}-${year} ${hours} : ${minuts}`)
console.log(`${year} / ${mount} / ${day} ${hours} : ${minuts}`)
```
## Exercise Level 3
1. Create a human readable time format using the Date time object. The hour and the minute should be all the time two digits(7 hours should be 07 and 5 minutes should be 05 )
```
- YYY-MM-DD HH:mm eg. 20120-01-02 07:05
```
```js
let now = new Date()
let year = now.getFullYear()
let mount = String(now.getMonth()+1).padStart(2,'0')
let day = String(now.getDate() ).padStart(2,'0')
let hour = String(now.getHours()).padStart(2,'0')
let minut = String(now.getMinutes()).padStart(2,'0')
console.log(`${day} / ${mount} / ${year} ${hour} : ${minut}`)
```
## [Home](../README.md) | [<< Day 2](./02_day_datatype.md) | [Day 4 >>](./04_day_conditional.md)

@ -0,0 +1,341 @@
# Exercise Day 2 -Conditionals
### [Exercises: Level 1](#exercise-level-1)
1. Get user input using prompt(“Enter your age:”). If user is 18 or older , give feedback:'You are old enough to drive' but if not 18 give another feedback stating to wait for the number of years he needs to turn 18.
```sh
Enter your age: 30
You are old enough to drive.
Enter your age:15
You are left with 3 years to drive.
```
1. Compare the values of myAge and yourAge using if … else. Based on the comparison and log the result to console stating who is older (me or you). Use prompt(“Enter your age:”) to get the age as input.
```sh
Enter your age: 30
You are 5 years older than me.
```
1. If a is greater than b return 'a is greater than b' else 'a is less than b'. Try to implement it in to ways
- using if else
- ternary operator.
```js
let a = 4
let b = 3
```
```sh
4 is greater than 3
```
1. Even numbers are divisible by 2 and the remainder is zero. How do you check, if a number is even or not using JavaScript?
```sh
Enter a number: 2
2 is an even number
Enter a number: 9
9 is is an odd number.
```
### [Exercises:Level 2](#exercise-level-2)
1. Write a code which can give grades to students according to theirs scores:
- 80-100, A
- 70-89, B
- 60-69, C
- 50-59, D
- 0-49, F
1. Check if the season is Autumn, Winter, Spring or Summer.
If the user input is :
- September, October or November, the season is Autumn.
- December, January or February, the season is Winter.
- March, April or May, the season is Spring
- June, July or August, the season is Summer
1. Check if a day is weekend day or a working day. Your script will take day as an input.
```sh
What is the day today? Saturday
Saturday is a weekend.
What is the day today? saturDaY
Saturday is a weekend.
What is the day today? Friday
Friday is a working day.
What is the day today? FrIDAy
Friday is a working day.
```
### [Exercises:Level 3](#exercise-level-3)
1. Write a program which tells the number of days in a month.
```sh
Enter a month: January
January has 31 days.
Enter a month: JANUARY
January has 31 day
Enter a month: February
February has 28 days.
Enter a month: FEbruary
February has 28 days.
```
1. Write a program which tells the number of days in a month, now consider leap year.
### Exercise Level 1
1. Get user input using prompt(“Enter your age:”). If user is 18 or older , give feedback:'You are old enough to drive' but if not 18 give another feedback stating to wait for the number of years he needs to turn 18.
```
Enter your age: 30
You are old enough to drive.
Enter your age:15
You are left with 3 years to drive.
```
```js
// app.js
let age = Number(prompt("lüefen yaşınızı giriniz"))
if(age >=18){
console.log(`Araba kullanabilecek yaştasınız`)
}
else(
console.log(`araba kullanabilmek için ${18-age} yıl beklemeniz gerekmektedir`)
)
```
2. Compare the values of myAge and yourAge using if … else. Based on the comparison and log the result to console stating who is older (me or you). Use prompt(“Enter your age:”) to get the age as input.
```
Enter your age: 30
You are 5 years older than me.
```
```js
// app.js
let myAge =18
let yourAge=18
if(myAge > yourAge ){
console.log(`ben senden ${myAge - yourAge} yıl büyüğüm`)
}
else if(myAge == yourAge){
console.log('aynı yaştayız')
}
else(
console.log(`sen benden ${yourAge - myAge} yıl büyüksün`)
)
```
3. If a is greater than b return 'a is greater than b' else 'a is less than b'. Try to implement it in to ways
```
- using if else
- ternary operator
let a = 4
let b = 3
```
```js
// app.js
let result =a > b
? console.log("a büyüktür b")
: console.log("b büyüktür a")
```
4. Even numbers are divisible by 2 and the remainder is zero. How do you check, if a number is even or not using JavaScript?
```
Enter a number: 2
2 is an even number
Enter a number: 9
9 is is an odd number.
```
```js
// app.js
let num = Number(prompt("sayı giriniz"))
if(num % 2 ==0){
console.log(`${num} sayısı çifttir`)
}
else{
console.log(`${num} sayısı tektir`)
}
```
### Exercise Level 2
1. Write a code which can give grades to students according to theirs scores:
```
- 80-100, A
- 70-89, B
- 60-69, C
- 50-59, D
- 0-49, F
```
```js
// app.js
let scores = Number(prompt("notunuzu giriniiz"))
if(80 <= scores && scores <=100 ){
console.log("notunuz ")
}
else if( 70 <= scores && scores <=79 ){
console.log("notunuz B")
}
else if( 60 <= scores && scores <=69 ){
console.log("notunuz C")
}
else if( 50 <= scores && scores <=59 ){
console.log("notunuz D")
}
else if( 0 <= scores && scores <=49 ){
console.log("notunuz E")
}
```
2. Check if the season is Autumn, Winter, Spring or Summer. If the user input is :
```
- September, October or November, the season is Autumn.
- December, January or February, the season is Winter.
- March, April or May, the season is Spring
- June, July or August, the season is Summer
```
```js
// app.js
const mount = String(prompt('hangi aydayız')).toLowerCase();
if(mount=='september' || mount=='october'|| mount=='november'){
console.log('The seson is Autumn')
}
else if(mount=='december' || mount=='january' || mount=='february'){
console.log('The season is Winter')
}
else if(mount=='march'||mount=='may' ||mount=='april'){
console.log('The season is Spring')
}
else if(mount=='june'||mount=='juli'||mount=='august'){
console.log('The seasom is Summer')
}
else{
console.log(`${mount} is not a mount`)
}
```
3. Check if a day is weekend day or a working day. Your script will take day as an input.
```
What is the day today? Saturday
Saturday is a weekend.
What is the day today? saturDaY
Saturday is a weekend.
What is the day today? Friday
Friday is a working day.
What is the day today? FrIDAy
Friday is a working day.
```
```js
// app.js
let day = prompt('What day is today').toLowerCase()
switch (day) {
case 'monday':
case 'tuesday':
case 'wednesday':
case 'thursday':
case 'friday':
console.log(`${day} is a workind day`)
break;
case 'sunday':
case 'saturday':
console.log(`${day} is weekend`)
break;
default: console.log(`${day} is't a day`)
}
```
### Exercise Level 3
1. Write a program which tells the number of days in a month.
```
Enter a month: January
January has 31 days.
Enter a month: JANUARY
January has 31 day
Enter a month: February
February has 28 days.
Enter a month: FEbruary
February has 28 days.
```
```js
// app.js
let month = prompt('Please enter a month')
switch (month) {
case 'january':
case 'march':
case 'may':
case 'july':
case 'august':
case 'october':
case 'december':
alert(`month has 31 day`)
}
switch(month){
case 'april':
case 'june':
case 'september':
case 'november':
alert(`month has 30 day`)
}
switch(month){
case 'february':
alert(`month has 28 day`)
}
```

@ -1,79 +0,0 @@
//---------------------------day1_level_1 1.exercise ------------------------\\
// Write a single line comment which says, comments can make code readable
// comments can make code readable
//---------------------------day1_level_1 2.exercise-------------------------\\
// Write another single comment which says, Welcome to 30DaysOfJavaScript
//Welcome to 30DaysOfJavaScript
//---------------------------day1_level_1 3.exercise-------------------------\\
// Write a multiline comment which says, comments can make code readable, easy
// to reuse and informative
/* comments can make code readable,
easy to reuse and informative */
//---------------------------day1_level_1 4.exercise-------------------------\\
// Create a variable.js file and declare variables and assign string, boolean,
// undefined and null data types
//variable.js
let string = 'nevzat'
let number = 25
let boolean = true
let nulll = null
let any; //undefined
//---------------------------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
//type.js
console.log(typeof (string) )
console.log(typeof (number))
console.log(typeof (boolean))
console.log(typeof (nulll))
console.log(typeof (any))
//---------------------------day1_level_1 6.exercise-------------------------\\
// Declare four variables without assigning values
let variable1;
let variable2;
var variable3;
let variable4;
//---------------------------day1_level_1 7. exercise------------------------\\
// Declare four variables with assigned values
variable1 = "nevzat"
variable2 = "ATALAY"
variable3 = true;
variable4 = 25;
//---------------------------day1_level_1 8.exercise-------------------------\\
// Declare variables to store your first name, last name, marital status,
// country and age in multiple lines
let firstName = "nevzat"
let lastName = "atalay"
let old = 25
let isMarried = true
//---------------------------day1_level_1 9.exercise-------------------------\\
// 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
//---------------------------day1_level_1 10.exercise------------------------\\
// Declare two variables myAge and yourAge and assign them initial values
// and log to the browser console.
let myAge= 25
let yourAge = 22
console.log("I am " + " " + myAge + " " + "years old.")
console.log("You are" + " " + yourAge + " " + "years old.")

@ -1,338 +0,0 @@
//----------------------------day2_level1 1.exercise-------------------------\\
// Declare a variable named challenge and assign it to an initial
//value '30 Days Of JavaScript'.
let challenge = '30 days of javascript'
//----------------------------day2_level1 2.exercise-------------------------\\
// Print the string on the browser console using console.log()
challenge = '30 days of javascript'
console.log(challenge)
//----------------------------day2_level1 3.exercise-------------------------\\
// Print the length of the string on the browser console using console.log()
challenge = '30 days of javascript'
console.log(challenge.length)
//----------------------------day2_level1 4.exercise-------------------------\\
// Change all the string characters to capital letters using toUpperCase()
method
challenge = '30 days of javascript'
console.log(challenge.toUpperCase())
//----------------------------day2_level1 5.exercise-------------------------\\
// Change all the string characters to lowercase letters using toLowerCase()
method
challenge = '30 days of javascript'
console.log(challenge.toLowerCase())
//----------------------------day2_level1 6.exercise-------------------------\\
// Cut (slice) out the first word of the string using substr() or substring()
method
challenge = '30 days of javascript'
console.log(challenge.substring(3, 5))
//----------------------------day2_level1 7.exercise-------------------------\\
// Slice out the phrase Days Of JavaScript from 30 Days Of JavaScript.
challenge = '30 days of javascript'
let newChallenge = challenge.slice(3,10)
console.log(newChallenge)
//----------------------------day2_level1 8.exercise-------------------------\\
// Check if the string contains a word Script using includes() method
challenge = '30 days of javascript'
console.log(challenge.includes('script'))
//----------------------------day2_level1 9.exercise-------------------------\\
// Split the string into an array using split() method
challenge = '30 days of javascript'
console.log(challenge.split(""))
//----------------------------day2_level1 10.exercise------------------------\\
// Split the string 30 Days Of JavaScript at the space using split() method
challenge = '30 days of javascript'
console.log(challenge.split(" "))
//----------------------------day2_level1 11.exercise------------------------\\
// 'Facebook, Google, Microsoft, Apple, IBM, Oracle, Amazon' split the string
//at the comma and change it to an array.
let companies = 'Facebook, Google, Microsoft, Apple, IBM, Oracle,Amazon'
console.log(companies.split(`,`))
//----------------------------day2_level1 12.exercise------------------------\\
// Change 30 Days Of JavaScript to 30 Days Of Python using replace() method.
challenge = "30 days of javascript"
console.log(challenge.replace("javascript","phyton"))
//----------------------------day2_level1 13.exercise------------------------\\
// What is character at index 15 in '30 Days Of JavaScript' string?
//Use charAt() method.
challenge = "30 days of javascript"
console.log(challenge.charAt(15))
//----------------------------day2_level1 14.exercise------------------------\\
// What is the character code of J in '30 Days Of JavaScript' string using
charCodeAt()
challenge = "30 days of javascript"
console.log(challenge.charCodeAt("j"))
//----------------------------day2_level1 15.exercise------------------------\\
// Use indexOf to determine the position of the first occurrence
//of a in 30 Days Of JavaScript
challenge = "30 days of javascript"
console.log(challenge.indexOf("a"))
//----------------------------day2_level1 16.exercise------------------------\\
// Use lastIndexOf to determine the position of the last occurrence of a in
//30 Days Of JavaScript.
challenge = "30 days of javascript"
console.log(challenge.lastIndexOf("a"))
//----------------------------day2_level1 17.exercise------------------------\\
// 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'
let sentence = "You cannot end a sentence with because because is a conjunction."
console.log(challenge.indexOf("because"))
//----------------------------day2_level1 18.exercise------------------------\\
// 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'
sentence = "You cannot end a sentence with because because is a conjunction."
console.log(challenge.lastIndexOf("because"))
//----------------------------day2_level1 19.exercise------------------------\\
// 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'
sentence = "You cannot end a sentence with because because is a conjunction."
console.log(challenge.search("because"))
//----------------------------day2_level1 20.exercise------------------------\\
// Use trim() to remove any trailing whitespace at the beginning and the end
//of a string.E.g ' 30 Days Of JavaScript '.
challenge = "30 Days Of JavaScript "
console.log(challenge.trim())
//----------------------------day2_level1 21.exercise------------------------\\
// Use startsWith() method with the string 30 Days Of JavaScript and make the
// result true
challenge = "30 Days Of JavaScript"
console.log(challenge.startsWith(30))
//----------------------------day2_level1 22.exercise------------------------\\
// Use endsWith() method with the string 30 Days Of JavaScript and make the
// result true
challenge = "30 Days Of JavaScript"
console.log(challenge.endsWith("JavaScript"))
//----------------------------day2_level1 23.exercise------------------------\\
// Use match() method to find all the as in 30 Days Of JavaScript
challenge = "30 Days Of JavaScript"
console.log(challenge.match("a"))
//----------------------------day2_level1 24.exercise------------------------\\
// Use concat() and merge '30 Days of' and 'JavaScript' to a single string,
'30 Days Of JavaScript'
let stringOne = "30 Days Of "
let stringTwo = "JavaScript"
console.log(stringOne.concat(stringTwo))
//----------------------------day2_level1 25.exercise------------------------\\
// Use repeat() method to print 30 Days Of JavaScript 2 times
challenge = "30 Days Of JavaScript"
console.log(challenge.repeat(2))
//____________________________starting_exercise_level2_______________________\\
//----------------------------day2_level2 1.exercise-------------------------\\
// Using console.log() print out the following statement:
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.`)
//----------------------------day2_level2 2.exercise-------------------------\\
// 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
love. Charity and love are the same -- with charity you give love, so don't
just give money but reach out your hand instead.`)
//----------------------------day2_level2 3.exercise-------------------------\\
// Using console.log() print out the following quote by Mother Teresa:
let number = "10"
console.log(number===10)
let number1 = 10
console.log(number1===10)
//----------------------------day2_level2 4.exercise-------------------------\\
// Check if parseFloat('9.8') is equal to 10 if not make it exactly
// equal with 10.
let parseNumber =parseFloat(9.8)
console.log(number===10)
let ceilNumber = Math.ceil(parseFloat(9.8))
console.log(number1===10)
//----------------------------day2_level2 5.exercise-------------------------\\
// Check if 'on' is found in both python and jargon
let string = "phyton"
let string1 ="jargon"
console.log(string.includes("on") && string1.includes("on"))
//----------------------------day2_level2 6.exercise-------------------------\\
// I hope this course is not full of jargon. Check if jargon is in the sentence.
let str = "I hope this course is not full of jargon."
console.log(str.includes("jargon"))
//----------------------------day2_level2 7.exercise-------------------------\\
// Generate a random number between 0 and 100 inclusively.
console.log(parseInt(Math.random()*101))
//----------------------------day2_level2 8.exercise-------------------------\\
// Generate a random number between 50 and 100 inclusively.
console.log(parseInt(Math.random()*51+50))
//----------------------------day2_level2 9.exercise-------------------------\\
// Generate a random number between 0 and 255 inclusively.
console.log(parseInt(Math.random()*255))
//----------------------------day2_level2 10.exercise------------------------\\
// Access the 'JavaScript' string characters using a random number.
let word="javasicript"
let n =parseInt(Math.random()*11)
console.log(word[n])
//----------------------------day2_level2 11.exercise------------------------\\
// Use console.log() and escape characters to print the following pattern.
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------------------------\\
// 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'
let statement = `You cannot end a sentence with because because because
is a conjunction`
console.log(statement.replace("because",""))
//____________________________starting_exercise_level3_______________________\\
//----------------------------day2_leve3 1.exercise--------------------------\\
// '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 strng =`Love is the best thing in this world. Some found their love and
some are still looking for their love.`
let count = strng.match(/love/gi)||[].length
console.log(count)
//----------------------------day2_leve3 2.exercise--------------------------\\
// 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'
let sentence1 = `You cannot end a sentence with because because because
is a conjunction`
let count1 = sentence1.match(/because/gi)||[].length
console.log(count1)
//----------------------------day2_leve3 3.exercise--------------------------\\
// Clean the following text and find the most frequent word
// (hint, use replace and regular expressions).
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&
@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!?
%Th#is 30#Days&OfJavaScript &is al@so $the $resu@lt of &love& of
tea&ching`;
let cleanSentence = messySentence.replace(/[^a-zA-Z ]/g, " ");
let words = cleanSentence.split(' ');
let wordCounts = {};
for(let i = 0; i < words.length; i++) {
if(words[i] !== '') {
wordCounts[words[i]] = (wordCounts[words[i]] || 0) + 1;
}
}
let maxWord = '';
let maxCount = 0;
for(let word in wordCounts) {
if(wordCounts[word] > maxCount) {
maxCount = wordCounts[word];
maxWord = word;
}
}
console.log(`Most frequent word is '${maxWord}' with count ${maxCount}`);
//----------------------------day2_leve3 4.exercise--------------------------\\
// 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
//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 numbers = text.match(pattern)
numbers = numbers.map(Number);
let montlySalary = numbers[0]
let bonus = numbers[1]
let montlyCourses = numbers[2]
console.log(`Annual income is ${montlySalary*12 +
bonus + montlyCourses *12} euro `)

@ -1,221 +0,0 @@
//todo day3_level1 1.exercise
// let name = "nevzat"
// let lastName = "atalay"
// let country = "turkey"
// let city = "bitlis"
// let age = 25
// let isMarried = true
// console.log(typeof(name),typeof(lastName),typeof(country),typeof(city),typeof(age),typeof(isMarried))
//todo day3_level1 2.exercise
// let number ="10"
// console.log(number==10)
//todo day3_level1 3.exercise
// let number = parseInt(9.8)
// console.log(number==10)
//todo day3_level1 4.exercise
// console.log(!!"merhaba")
// console.log(!!1)
// console.log(!![])
// console.log(!!"")
// console.log(!!0)
// console.log(!!null)
//todo day3_level1 5.exercise
// const arr = [
// 4 > 3,
// 4 >= 3,
// 4 < 3,
// 4 <= 3,
// 4 == 4,
// 4 === 4,
// 4 != 4,
// 4 !== 4,
// 4 != '4',
// 4 == '4',
// 4 === '4',
// ]
// console.log(arr)
// let string = "phyton", string1 = "jargon"
// console.log(string.length >= string1.length )
//todo day3_level1 6.exercise
/*
const arr = [
4 > 3 && 10 < 12,
4 > 3 && 10 > 12,
4 > 3 || 10 < 12,
4 > 3 || 10 > 12,
!(4 > 3),
!(4 < 3),
!(false),
!(4 > 3 && 10 < 12),
!(4 > 3 && 10 > 12),
!(4 === '4')]
console.log(arr)
*/
// let string = "phyton", string1 = "jargon"
// console.log(string.includes("on") && string1.includes("on"))
//todo day3_level1 7.exercise
// let now = new Date()
// console.log(now.getFullYear())
// console.log(now.getMonth()+1)
// console.log(now.getDay())
// console.log(now.getHours())
// console.log(now.getMinutes())
// console.log(now.getTime())
//? day3_level2 1.exercise
// let width =Number(prompt("üçgenin genişligini giriniz"))
// let height =Number(prompt("üçgenin yğksekliğini giriniz"))
// let area = width*height / 2
// console.log(area)
//? day3_level2 2.exercise
// let width =Number(prompt("üçgenin a kenarını giriniz"))
// let height =Number(prompt("üçgenin yüksekliğini giriniz"))
// let widthb = Number(prompt("üçgenin b kenarını giriniz"))
// let perimeter = width+height+widthb
// console.log(perimeter)
//? day3_level2 3.exercise
// let width = Number(prompt("dikdörtgenin genişliğini giriniz"))
// let height = Number(prompt("dikdörtgenin yüksekliğini giriniz"))
// let perimeter = 2*(width+height)
// console.log(perimeter)
//? day3_level2 4.exercise
// let r = 5
// let area = Math.PI * r**2
// console.log(area)
//? day3_level2 5.exercise
// let slope = 2 //x in katsayısı egimi verir
// let x_intercept = 1
// let y_intercept = 2
// console.log(`denklemin eğimi ${slope}, x in kesme noktası ${x_intercept}, y nin kesme noktası ${y_intercept} dir`)
//? day3_level2 6.exercise
// let x1 =2 , x2 = 6
// let y1 = 2 ,y2 =10
// let slope =( y2 - y1 ) / (x2 - x1)
// console.log(slope)
//? day3_level2 7.exercise
// let slope1 = 2
// let slope2 = 2
// console.log(slope1==slope2)
//? day3_level2 8.exercise
// let y = (x + 3)**2
// let x = [-3,-2,-1,0,1,2,3]
// y nin 0 debuggeri için x -3tür
//? day3_level2 9.exercise
// let hours = Number(prompt("günde kaç saat çalışıyorsunuz"))
// let workingWage = Number(prompt("saatlik çalışma ücretinizi giriniz"))
// let wage = hours*workingWage*30
// console.log(`maaşınız ${wage} tl dir`)
//? day3_level2 10.exercise
// let myName = "nevzat"
// if(myName.length > 7){
// console.log("adınız uzundur")
// }
// else{
// console.log("adınız kıssadır")
// }
//? day3_level2 11.exercise
// let myName = "nevzat"
// let myLastName = "talay"
// if(myName.length > myLastName.length){
// console.log(`adınız nevzat soyadınız atalaydan daha uzundur`)
// }
// else{
// console.log("soyadınız atalay adınız nevzattan daha uzundur")
// }
//? day3_level2 12.exercise
// let myAge =25
// let yourAge =18
// let message = myAge - yourAge > yourAge - myAge ? "ben senden büyüğüm" : "sen benden büyüksün"
// console.log(message)
//? day3_level2 13.exercise
// let birtYear = Number(prompt("doğum yılınızı giriniz"))
// let now = new Date()
// let year = now.getFullYear()
// let age = year - birtYear
// if(age >=18){
// console.log("ehliyet sınavına başvuru yapabilirsiniz")
// }
// else{
// console.log(`ehliyet sınavına başvuru yapabilmeniz için ${18-age} yıl beklemeniz gerekmektedir`)
// }
//? day3_level2 14.exercise
// let age = Number(prompt("kaç yaşındasınız"))
// let lastSecond = age*365*24*60*60
// let remainingSeconds = (100*365*24*60*60) - (lastSecond)
// console.log(`en fazla ${remainingSeconds} saniye ömrÜn kaldı WAKW UP`)
//? day3_level2 15.exercise
// let now = new Date()
// let year = now.getFullYear()
// let mount = now.getMonth()
// let day = now.getDay()
// let hours = now.getHours()
// let minuts = now.getMinutes()
// console.log(`${year}-${mount}-${day} ${hours} : ${minuts}`)
// console.log(`${day}-${mount}-${year} ${hours} : ${minuts}`)
// console.log(`${year} / ${mount} / ${day} ${hours} : ${minuts}`)
//! day3_level3 1.exercise
// let now = new Date()
// let year = now.getFullYear()
// let mount = String(now.getMonth()+1).padStart(2,'0')
// let day = String(now.getDate() ).padStart(2,'0')
// let hour = String(now.getHours()).padStart(2,'0')
// let minut = String(now.getMinutes()).padStart(2,'0')
// console.log(`${day} / ${mount} / ${year} ${hour} : ${minut}`)
Loading…
Cancel
Save