Skip to content

Commit 7f9ae36

Browse files
committed
Homework completed JS1,W3-Rodias
1 parent a3a6600 commit 7f9ae36

2 files changed

Lines changed: 106 additions & 0 deletions

File tree

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
2+
let cardNum='0211111111111112';
3+
4+
checkCardParameters(cardNum);
5+
6+
function checkCardParameters(item){
7+
// let strItem=item.toString();
8+
for (let i=0; i<item.toString().length;i++){
9+
var numb=item[i];
10+
numb=Number.parseInt(numb); //changes the strings to numbers
11+
}
12+
var numArray=item.toString().split('') ;
13+
14+
if (item.toString().length===16){ //by this condition we check that the number is only 16 digit long
15+
let count = 0;
16+
let sumD=0;
17+
for (var i=0; i<item.toString().length;i++){
18+
// all the digits cannot be the same
19+
if (numArray[0]===numArray[i]){
20+
count++;
21+
}
22+
if (count===16){
23+
console.log("Revise! All of the digits cannot be the same")
24+
}
25+
sumD+= Number(numArray[i]);
26+
}
27+
if (sumD<=16){
28+
console.log("The sum of all the digits must be greater than 16")
29+
}
30+
//The final digit must be even
31+
if (numArray[15] % 2 == true){
32+
console.log("The last digit should be even number")
33+
};
34+
} else {
35+
console.log("You should insert a 16-digit number")
36+
}
37+
}
38+
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// ----------------Exercise 1: You are amazing, Noer!----------
2+
function giveCompliment(name){
3+
let compArray=['great', 'awesome', 'outstanding',
4+
'considerable','magnificent','prominent','enthusiastic',
5+
'absolute','powerful','enjoyable'];
6+
var randComp= compArray[Math.floor(Math.random() * compArray.length)];
7+
return console.log(`You are ${randComp}, ${name}`)
8+
}
9+
giveCompliment("Efthymis");
10+
giveCompliment("Efthymis");
11+
giveCompliment("Efthymis");
12+
13+
// ----------------Exercise 2: Dog years------------------
14+
15+
function calculateDogAge(age){
16+
dogAge=Math.round(age/7);
17+
// fixedDogAge=dogAge.toFixed(1);
18+
return console.log(`Your doggie is ${dogAge} years old in dog years`)
19+
}
20+
21+
calculateDogAge(9);
22+
calculateDogAge(29);
23+
calculateDogAge(47);
24+
25+
// ----------------Exercise 3: Be your own fortune teller------------------
26+
function tellFortune(childrenQuantity, partner,place,jobTitle){
27+
28+
var randChildren=numChildren[Math.floor(Math.random() * numChildren.length)];
29+
var randPartNames=partnerNames[Math.floor(Math.random() * partnerNames.length)];
30+
var randLocations=locations[Math.floor(Math.random() * locations.length)];
31+
var randJobs=jobs[Math.floor(Math.random() * jobs.length)];
32+
33+
return console.log(`You will be a ${randJobs} in ${randLocations}, and married to ${randPartNames} with ${randChildren} kids.`)
34+
}
35+
let numChildren=[2, 4, 3, 1, 5];
36+
let partnerNames=["John", "George", "Mike", "Remi", "Eddie"];
37+
let locations =["Athens", "Volos", "Chania","Patra", "Corfu"];
38+
let jobs=["technician", "software engineer", "plumber", "doctor", "waiter"];
39+
40+
tellFortune(numChildren,partnerNames,locations,jobs);
41+
42+
// ----------------Exercise 4: Shopping at the supermarket------------------
43+
44+
function addToShoppingCart(item){
45+
// let cartArray=[];
46+
cartArray.push(item);
47+
if (cartArray.length>3){
48+
cartArray.shift();
49+
}
50+
console.log(`You bought ${cartArray}!`)
51+
}
52+
let cartArray=["bananas","milk"];
53+
addToShoppingCart("yoghurt");
54+
addToShoppingCart("rice");
55+
addToShoppingCart("ham");
56+
57+
// ----------------Exercise 5: Total cost is... ------------------
58+
59+
function calculateTotalPrice(objectsCart){
60+
let sum=0;
61+
for (const value in objectsCart){
62+
sum += objectsCart[value];
63+
}
64+
console.log(`Total cost is ${sum.toFixed(2)}.`);
65+
}
66+
67+
cartForParty={beers:1.75, chips:0.99, wine:5, nachos:1.5, vodka:12}
68+
calculateTotalPrice(cartForParty);

0 commit comments

Comments
 (0)