Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d25ecb6

Browse files
authored
Merge pull request #4 from Armigerousmonk/master
AmirHossein-Javascript1-Week1-Homework
2 parents 9c75092 + 5819c42 commit d25ecb6

File tree

13 files changed

+213
-2
lines changed

13 files changed

+213
-2
lines changed

.gitignore

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
.idea
2-
.DS_Store
3-
.vscode/launch.json
2+
master
3+
.Dstore
4+
.vscode/lunch.jason
5+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
let drinkTray = [];
2+
const drinkTypes = ['cola', 'lemonade', 'water'];
3+
let pointer = 0;
4+
let count = 0;
5+
while (drinkTray.length < 5) {
6+
drinkTray.push(drinkTypes[pointer])
7+
count++;
8+
if (count ==2) {
9+
pointer++;
10+
count = 0;
11+
};
12+
if (pointer >= drinkTypes.length) {
13+
pointer = 0;
14+
};
15+
};
16+
console.log(`Hey guys, I brought a ${drinkTray}!`);
17+
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
function calculategrades(gradeInput) {
2+
let result = 0;
3+
let gPercent = `${(gradeInput * 100) / 100}%`; //using this calculation to make the percentage of the grade.
4+
switch (Math.floor(gradeInput/10)) { //Using Math.floor to round grades to largest integer and then read the reletive condition in the switch.
5+
case 9:
6+
result = "A";
7+
break;
8+
case 8:
9+
result = "B"
10+
break;
11+
case 7:
12+
result = "C"
13+
break;
14+
case 6:
15+
result = "D"
16+
break;
17+
case 5:
18+
result = "E"
19+
break;
20+
case 4:
21+
result = "F"
22+
break;
23+
case 3:
24+
result = "F"
25+
break;
26+
case 2:
27+
result = "F"
28+
break;
29+
case 1:
30+
result = "F"
31+
break;
32+
case 0:
33+
result = "F"
34+
break;
35+
}
36+
return `You got a ${result} (${gPercent})!`
37+
}
38+
let x = calculategrades(60);
39+
console.log(x);
40+
41+
42+
// console.log(`${grades(1)}`)
43+
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
'use strict'
2+
let books = [
3+
{
4+
title: "The Three Musketeers",
5+
author: "Alexandre Dumas",
6+
alreadyRead: true,
7+
},
8+
{
9+
title: "Harry Potter",
10+
author: "J.K Rolling",
11+
alreadyRead: false,
12+
},
13+
{
14+
title: "Deep Work",
15+
author: "Kal Newport",
16+
alreadyRead: false,
17+
}
18+
]
19+
20+
21+
22+
books.forEach((element, index, array) => {
23+
console.log(element.title + " by " + element.author);
24+
if (element.alreadyRead) {
25+
console.log("You already read " + element.title)
26+
} else {
27+
console.log("You still need to read " + element.title)
28+
};
29+
});
30+
31+
32+
33+
34+
35+
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
"use strict"
2+
let recipe = {
3+
mealName : "Mirzaghasemi",
4+
serves: 2,
5+
ingredients : ["2 eggplants", "2 eggs", "1 garlic"]
6+
};
7+
let x = ['Meal name', 'Serves', 'Ingredients']
8+
//Method1:
9+
// for (let property in recipe) {
10+
// console.log(property + ": " + recipe[property]);
11+
// };
12+
13+
//Method2:
14+
// for (let property in recipe) {
15+
// console.log(`${property}: ${recipe[property]}`);
16+
// };
17+
18+
//Method3:
19+
let property = Object.keys(recipe);
20+
let value = Object.values(recipe);
21+
22+
for (let i = 0; i < Object.keys(recipe).length; i++) {
23+
24+
console.log(x[i] + ": " + value[i]);
25+
26+
};
27+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
'use strict';
2+
var myString = 'hello,this,is,a,difficult,to,read,sentence';
3+
console.log(myString.length);
4+
var index = myString.replace(/,/g , " ")
5+
console.log(index)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
"use strict"
2+
for (let i = 0; i < 20 ; i++) {
3+
if (i % 2 == 0) {
4+
console.log("The number " + i + " is even");
5+
} else {
6+
console.log("The number " + i + " is odd")
7+
}
8+
};
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
'use strict'
2+
const cartForParty = {
3+
beer: 1,
4+
chips: 2,
5+
fruits: 3,
6+
dough: 4,
7+
water: 5
8+
}
9+
10+
let total = 0;
11+
function calculateTotalPrice(item) {
12+
for (let i = 0; i < Object.keys(item).length; i++) {
13+
14+
const arrValues = Object.values(item);
15+
total += arrValues[i];
16+
17+
};
18+
const result = console.log(`Total: €${total}`);
19+
return result;
20+
};
21+
22+
calculateTotalPrice(cartForParty);
23+
24+
25+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
function calculateDogAge(age) {
2+
const doggyage = age * 7;
3+
const result = console.log(doggyage);
4+
return result;
5+
};
6+
calculateDogAge(3);
7+
calculateDogAge(2);
8+
calculateDogAge(4);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
node const numChildren = [1, 2, 3, 4, 5];
2+
const partnerNames = ['Ali', 'Amir', 'Lili', 'Mina', 'Masood'];
3+
const locations = ['Iran', 'USA', 'Holland', 'UK', 'Jordan'];
4+
const jobs = ['Doctor', 'Programmer', 'Killer', 'Police', 'President'];
5+
function tellFortune(numChildren, partnerNames, locations, jobs){
6+
const randomNum = numChildren[Math.floor(Math.random() * numChildren.length)];
7+
const randomName = partnerNames[Math.floor(Math.random() * partnerNames.length)];
8+
const randomLocation = locations[Math.floor(Math.random() * locations.length)];
9+
const randomJob = jobs[Math.floor(Math.random() * jobs.length)];
10+
11+
console.log(`You will be a ${randomJob} in ${randomLocation}, married to ${randomName} with ${randomNum} kids.`)
12+
};
13+
14+
tellFortune(numChildren, partnerNames, locations, jobs);
15+
tellFortune(numChildren, partnerNames, locations, jobs);
16+
tellFortune(numChildren, partnerNames, locations, jobs);
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
'use strict'
2+
const compliments = ["great", "amazing", "wonderful", "lamentable", "attractive", "merciful", "fair" , "spectacular", "dynamic", "elegant"];
3+
function giveCompliment(name) {
4+
5+
const randCompliment = compliments[Math.floor(Math.random() * compliments.length)];
6+
const result = console.log(`You are ${randCompliment}, ${name}!`)
7+
return result; //Am I using return correctly here?
8+
};
9+
giveCompliment('ali')
10+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
'use strict'
2+
const shoppingCart = ['bananas', 'milk'];
3+
function addToShoppingCart(item){
4+
shoppingCart.push(item);
5+
for(let i = 0; i < shoppingCart.length; i++) {
6+
if (shoppingCart.length > 3) {
7+
shoppingCart.shift();
8+
}
9+
};
10+
const result = console.log(`You bought ${shoppingCart}!`);
11+
return result;
12+
};
13+
addToShoppingCart('chocolate');
14+
addToShoppingCart('waffles');
15+
addToShoppingCart('tea');

Week3/text.js

Whitespace-only changes.

0 commit comments

Comments
 (0)