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

Skip to content

Commit 6008f8c

Browse files
committed
submet Homework week-3
1 parent 4533787 commit 6008f8c

7 files changed

+171
-0
lines changed

Week2/.DS_Store

6 KB
Binary file not shown.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
'use strict'
2+
const giveCompliment = (yourName)=> {
3+
let compliments = [
4+
"great",
5+
"awesome",
6+
"On a scale from 1 to 10, you’re an 100",
7+
"a great listener",
8+
"Aside from food. You’re my favorite",
9+
"That color is perfect on you",
10+
"stunning",
11+
"cool",
12+
"the best",
13+
"one of a kind!",
14+
];
15+
let compliment = Math.floor(Math.random() * compliments.length)
16+
return `You are ${compliments[compliment]}, ${yourName}!`;
17+
}
18+
console.log(giveCompliment("Sadeq"));
19+
console.log(giveCompliment("Hadeer"));
20+
console.log(giveCompliment("Iya"));

Week3/homework/2: Dog years.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
'use strict'
2+
const calculateDogAge =(age)=>{
3+
let dogAge = age * 7 ;
4+
return `Your doggie is ${dogAge} years old in dog years!`;
5+
}
6+
console.log(calculateDogAge(27));
7+
console.log(calculateDogAge(20));
8+
console.log(calculateDogAge(2));
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
'use strict'
2+
let numChildren = ["Iya","Sara","Marian","Daved","Maikul"];
3+
let partnerNames = ["Greet","Samer","Sadeq","Hadeer","Marian"];
4+
let locations = ["Baghdad","London","Sneek","Arnhem","Harderwijk"];
5+
let jobs = ["Architect","Developer","Desiner","Doctor","writer"];
6+
7+
const tellFortune = (childrenNum,partnerNam,location,theJob)=>{
8+
9+
let childrenNumber = childrenNum[ Math.floor(Math.random() * childrenNum.length)];
10+
let partnerName = partnerNam[ Math.floor(Math.random() * partnerNam.length)];
11+
let locationName = location[ Math.floor(Math.random() * location.length)];
12+
let jobsName = theJob[ Math.floor(Math.random() * theJob.length)];
13+
14+
return `"You will be a ${jobsName} in ${locationName}, married to ${partnerName} with ${childrenNumber} kids."`
15+
}
16+
console.log(tellFortune(numChildren,partnerNames,locations,jobs))
17+
console.log(tellFortune(numChildren,partnerNames,locations,jobs))
18+
console.log(tellFortune(numChildren,partnerNames,locations,jobs))
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
'use strict';
2+
3+
let shoppingCart = ['bananas', 'milk'];
4+
const addToShoppingCart = (item) => {
5+
shoppingCart.push(item);
6+
if (shoppingCart.length > 3) {
7+
shoppingCart.shift();
8+
}
9+
return `You bought ${shoppingCart[0]}, ${shoppingCart[1]}, ${shoppingCart[2]} !`;
10+
};
11+
12+
console.log(addToShoppingCart('apple')); // Returns "You bought bananas, milk, chocolate!"
13+
console.log(addToShoppingCart('choclet')); // Returns "You bought bananas, milk, chocolate!" */
14+
console.log(addToShoppingCart('water')); // Returns "You bought bananas, milk, chocolate!" */
15+
16+
for (let i = 0; i < shoppingCart.length; i++) {
17+
console.log(shoppingCart[i]);
18+
}
19+

Week3/homework/5: Total cost is.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
'use strict'
2+
let cartForParty = {
3+
chips: 0.9,
4+
chocolate: 2.3,
5+
banana: 0.3,
6+
cola: 1.6,
7+
water: 0.5
8+
9+
}
10+
const calculateTotalPrice = (object)=>{
11+
let total = 0 ;
12+
for (let i in object){
13+
total += object[i];
14+
15+
}
16+
return `Total: €${total}`;
17+
}
18+
19+
console.log(calculateTotalPrice(cartForParty));
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
'use strict'
2+
3+
//1- Input must be 16 characters
4+
function checkLength(credit){
5+
if(credit.length !== 16 ){
6+
return `Invalid! The input ${credit} must be 16 digites!`;
7+
}
8+
}
9+
10+
//2- All characters must be numbers
11+
function checkTheTypeOf(credit){
12+
13+
for(let i = 0 ; i< credit.length ; i++ ){
14+
15+
let theNumber = parseFloat(credit[i]);
16+
17+
18+
if(isNaN(theNumber)){
19+
return `Invalid! The input ${credit} should contain only numbers`;
20+
21+
}
22+
}
23+
24+
}
25+
26+
// 3- At least two different numbers should be represented.
27+
function checkSimilarNumber(credit){
28+
29+
let reversestr = (str) => [...str];
30+
31+
let newArray = reversestr(credit);
32+
33+
const checkTheNumber = newArray.every(function(element){
34+
return (element == newArray[newArray.length-1]);
35+
36+
37+
});
38+
if(checkTheNumber){
39+
return `Invalid! The input ${credit} should contain at least 2 different types of numbers`;
40+
}
41+
}
42+
43+
44+
//4- The last number must be even.
45+
function checkTheLastNumber(credit){
46+
47+
let lastNumber = parseFloat(credit[credit.length-1]);
48+
49+
// return lastNumber;
50+
if(lastNumber % 2 !== 0){
51+
return `Invalid! The input ${credit} the last number should shoud be even`;
52+
}
53+
}
54+
55+
// 5- The sum of all the numbers must be greater than 16
56+
function checkTheTotal(credit){
57+
58+
59+
let total = 0;
60+
61+
for(let i = 0 ; i< credit.length ; i++ ){
62+
let theNumber = parseFloat(credit[i]);
63+
total += theNumber;
64+
}
65+
66+
if(total <= 16){
67+
return `Invalid! The input ${credit} should be greater than 16`;
68+
}
69+
}
70+
71+
72+
73+
function validateCreditNumber(credit){
74+
return checkLength(credit) ||
75+
checkTheTypeOf(credit) ||
76+
checkSimilarNumber(credit) ||
77+
checkTheLastNumber(credit) ||
78+
checkTheTotal(credit);
79+
80+
}
81+
82+
83+
console.log(validateCreditNumber('11111a111111111111'))
84+
85+
86+
87+

0 commit comments

Comments
 (0)