Skip to content

Commit 65b225a

Browse files
committed
Finished Homework week2 SAMED OZCAN
1 parent ef850fd commit 65b225a

6 files changed

Lines changed: 144 additions & 0 deletions

File tree

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/* We made a function which takes score, evaluates between 0-100, assigns a grade letter
2+
according two American grade system. */
3+
4+
function calculateGrade(score) {
5+
let grade = '';
6+
7+
if (score >= 90 && score <= 100) {
8+
grade = 'A';
9+
} else if (score >= 80 && score < 90) {
10+
grade = 'B';
11+
} else if (score >= 70 && score < 80) {
12+
grade = 'C';
13+
} else if (score >= 60 && score < 70) {
14+
grade = 'D';
15+
} else if (score >= 50 && score < 60) {
16+
grade = 'E';
17+
} else if (score >= 0 && score < 50) {
18+
grade = 'F';
19+
} else {
20+
grade = 'n/a'; //not available
21+
}
22+
23+
return `You got a ${grade} (${score}%)!`;
24+
}
25+
26+
console.log(calculateGrade(100));
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
'use strict';
2+
console.log('EXERCISE 1 - Remove The Comma');
3+
4+
/* EXERCISE-1 =>
5+
In this exercise we want to remove all the commas and replace them with spaces.
6+
So I used google for my searching and I found the answer in stackoverflow.com
7+
https://stackoverflow.com/questions/39345634/how-do-i-replace-all-spaces-commas-and-periods-in-a-variable-using-javascript/39346082
8+
To achieve this, we should use regular expressions(regex).
9+
It has 2 parameters, first one is what we want to change,
10+
and the second parameter is the replacing ones.
11+
In the end our sentence is "hello this is a difficult to read sentence"*/
12+
13+
let myString = 'hello,this,is,a,difficult,to,read,sentence';
14+
console.log('The length of my string is ' + myString.length);
15+
myString = myString.replace(/[","]/g, ' ');
16+
console.log(myString);
17+
18+
console.log('------------');
19+
/* Or we can do this with using split method and join method */
20+
21+
let myString2 = 'hello,this,is,a,difficult,to,read,sentence';
22+
console.log('The length of my string is ' + myString.length);
23+
let splittedString = myString.split(',');
24+
console.log(splittedString);
25+
myString = splittedString.join(' ');
26+
console.log(myString);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
'use strict';
2+
console.log('EXERCISE 2 - The even/odd reporter');
3+
4+
/* EXERCISE-2 =>
5+
First we made a for loop which iterates 0 to 20.
6+
Then we made an if + else statement to check if our number is odd or even.
7+
To do this we used remainder/modulo operator.
8+
finally we console.log our numbers. ta da...*/
9+
10+
for (let i = 0; i <= 20; i++) {
11+
if (i % 2 === 1) {
12+
console.log('The number ' + i + ' is odd!');
13+
} else {
14+
console.log(`The number ${i} is even!`);
15+
}
16+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
'use strict';
2+
console.log('EXERCISE 3 - The Recipe Card');
3+
4+
/* EXERCISE-3 =>
5+
First of all we made an object with 3 properties.
6+
Then we logged out the properties using loop. */
7+
8+
let myMealRecipe = {
9+
nameOfMeal: 'meat saute',
10+
serves: 4,
11+
ingredients: ['1 kg meat', '7 tomatoes', '11 pepper', 'salt'],
12+
};
13+
14+
console.log(`Meal name: ${myMealRecipe.nameOfMeal}`); // 'Meal name: ' + myMealRecipe.nameOfMeal
15+
console.log(`Serves: ${myMealRecipe.serves}`);
16+
console.log('Ingredients:');
17+
for (let i = 0; i < myMealRecipe.ingredients.length; ++i) {
18+
console.log(myMealRecipe.ingredients[i]);
19+
}
20+
21+
/* Or we can do this with for..of..loop
22+
23+
for (let ingredient of myMealRecipe.ingredients) {
24+
console.log(ingredient);
25+
}
26+
*/
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
'use strict';
2+
console.log('EXERCISE 4 - The reading list');
3+
4+
/* EXERCISE-4 => */
5+
6+
/* First we creat our objects, then using for loop and if
7+
we can log our reading list. */
8+
9+
let myBookList = [
10+
{
11+
title: 'The Count of Monte Cristo',
12+
author: 'Alexander Dumas',
13+
alreadyRead: true,
14+
},
15+
{
16+
title: 'Les Misarebles',
17+
author: 'Victor Hugo',
18+
alreadyRead: true,
19+
},
20+
{
21+
title: 'The Hobbit',
22+
author: 'J.R.R. Tolkien',
23+
alreadyRead: false,
24+
},
25+
];
26+
27+
for (let i = 0; i < myBookList.length; ++i) {
28+
console.log(myBookList[i].title + ' by ' + myBookList[i].author);
29+
if (myBookList[i].alreadyRead) {
30+
console.log(`You already read "${myBookList[i].title}"`);
31+
} else {
32+
console.log(`You still need to read "${myBookList[i].title}"`);
33+
}
34+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
'use strict';
2+
console.log('EXERCISE 5 - Who wants a drink?');
3+
4+
/* EXERCISE-5 => */
5+
6+
/* We declared our empty array, then with for loop
7+
we pushed our drinkTypes. Finally with back tick we logged our sentence. */
8+
9+
let drinkTray = [];
10+
const drinkTypes = ['cola', 'lemonade', 'water'];
11+
12+
for (let i = 0; i < 5; ++i) {
13+
drinkTray.push(drinkTypes[i % 3]);
14+
}
15+
16+
console.log('Hey guys, I brought a ' + drinkTray.join(', ') + '!');

0 commit comments

Comments
 (0)