Skip to content

Commit ceb30fb

Browse files
committed
Merge branch 'fadialset-w3'
2 parents 903d72d + 9a8cbcf commit ceb30fb

6 files changed

Lines changed: 198 additions & 0 deletions

File tree

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
'use strict'
2+
//My way to solve the project
3+
4+
function validateSumIsLargerThan16(number) {
5+
var sum = 0;
6+
for(let i = 0; i < number.length; i++) {
7+
sum = sum + Number.parseInt(number[i]);
8+
}
9+
return sum > 16;
10+
} // this function Inou teached it to us I was stuck with knowing how to do the sum
11+
12+
function validateCreditNumber(number){
13+
const regexTwoDiffNumbersCCNum = /^(\d)\1*$/.test(number);
14+
// Input must be 16 characters
15+
if (number.length !== 16){
16+
console.log(`Invalid! The input ${number} charecters must be 16`)
17+
}else if (isNaN(number)){
18+
// All characters must be numbers
19+
console.log(`Invalid! The input ${number} should contain only numbers`)
20+
}else if (regexTwoDiffNumbersCCNum){
21+
// At least two different numbers should be represented
22+
console.log(`Invalid! The input ${number} should contain at least 2 different types of numbers!`);
23+
}else if (number % 2 !== 0) {
24+
// The last number must be even
25+
console.log(`Invalid! The input ${number} last number must be even`);
26+
}else if (!validateSumIsLargerThan16(number)){
27+
28+
29+
// The sum of all the numbers must be greater than 16
30+
console.log(`Invalid! The input ${number} charecters sum must be greater than 16`);
31+
}else{
32+
console.log(`Success! The input ${number} is a valid credit card number!`);
33+
}
34+
};
35+
36+
console.log(validateCreditNumber('a92332119c011122'));
37+
console.log(validateCreditNumber('4444444444444444'));
38+
console.log(validateCreditNumber('1111111111111110 '));
39+
console.log(validateCreditNumber('6666666666661666'));
40+
console.log(validateCreditNumber('9999777788880000'));
41+
42+
43+
44+
/////////////////////// what Inou teached us////////////////////
45+
46+
47+
/*
48+
function validateAllChsAreNumbers(number) {
49+
const parsedNumber = Number.parseInt(number);
50+
const isNumber = Number.isInteger(parsedNumber);
51+
return isNumber && parsedNumber.toString().length === number.length;
52+
}
53+
54+
function validateDifferentElements(number) {
55+
var occurences = {};
56+
for(let i = 0; i < number.length; i++) {
57+
occurences[number[i]] = undefined;
58+
}
59+
var uniqueValues = Object.keys(occurences);
60+
return uniqueValues.length > 1;
61+
}
62+
63+
64+
function validateSumIsLargerThan16(number) {
65+
var sum = 0;
66+
for(let i = 0; i < number.length; i++) {
67+
sum = sum + Number.parseInt(number[i]);
68+
}
69+
return sum > 16;
70+
}
71+
72+
73+
function isEven(number) {
74+
return number % 2 === 0;
75+
}
76+
77+
78+
function validateCreditNumber(number) {
79+
if (number.length !== 16) {
80+
console.log(`Invalid! The input ${number} charecters must be 16`);
81+
}else if (! validateAllChsAreNumbers(number)) {
82+
console.log(`Invalid! The input ${number} should contain only numbers`);
83+
}else if (! validateDifferentElements(number)) {
84+
console.log(`Invalid! The input ${number} should contain at least 2 different types of numbers!`);
85+
}else if (! validateSumIsLargerThan16(number)) {
86+
console.log(`Invalid! The input ${number} charecters sum must be greater than 16`);
87+
}else if (! isEven(number[number.length - 1])) {
88+
console.log(`Invalid! The input ${number} last number must be even`);
89+
}else
90+
console.log(`Success! The input ${number} is a valid credit card number!`);
91+
}
92+
93+
console.log(validateCreditNumber('a92332119c011112'));
94+
console.log(validateCreditNumber('4444444444444444'));
95+
console.log(validateCreditNumber('6666666666661666'));
96+
*/
97+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
'use strict'
2+
function giveCompliment(name){
3+
const complemnts = ['great','awsome','amazing','incredible','lovley','cute','atractive','handsome','pretty','fantastic'];
4+
const randomItem = complemnts[Math.floor(Math.random()*complemnts.length)];
5+
return `You are ${randomItem}, ${name}`
6+
}
7+
8+
giveCompliment('Inou');
9+
giveCompliment('Tjebbe');
10+
giveCompliment('Darlene');
11+
12+
// console.log(giveCompliment('Inou'));
13+
// console.log(giveCompliment('Tjebbe'));
14+
// console.log(giveCompliment('Darlene'));
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
'use strict'
2+
function calculateDogAge(number){
3+
const DogAgeInDogYears = number * 7;
4+
return `your doggis is ${DogAgeInDogYears } years old in dog years!`;
5+
}
6+
7+
calculateDogAge(1);
8+
calculateDogAge(2);
9+
calculateDogAge(3);
10+
11+
// console.log(calculateDogAge(1));
12+
// console.log(calculateDogAge(2));
13+
// console.log(calculateDogAge(3));
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
'use strict'
2+
const numChildren = [1,2,3,4,5];
3+
const partnerNames = ['Margot Robbi','Charlize theorn','Emilia clarck','Scarlet johansen','Monica bolutchi'];
4+
const locations = ['Amsterdam','Rotterdam','Utrecht','Enschede','NewYork'];
5+
const jobs = ['Front-End developer','Back-End developer','Full-stack developer','JAVA developer','PHP developer'];
6+
7+
function tellFortune(numChildren, partnerNames, locations, jobs){
8+
let randomChild = numChildren[Math.floor(Math.random()*numChildren.length)];
9+
let randomPartner = partnerNames[Math.floor(Math.random()*partnerNames.length)];
10+
let randomLocation = locations[Math.floor(Math.random()*locations.length)];
11+
let randomJob = jobs[Math.floor(Math.random()*jobs.length)];
12+
return `You will be a ${randomJob} in ${randomLocation}, marrid to ${randomPartner} with ${randomChild} kids.`
13+
}
14+
tellFortune(numChildren, partnerNames, locations, jobs);
15+
tellFortune(numChildren, partnerNames, locations, jobs);
16+
tellFortune(numChildren, partnerNames, locations, jobs);
17+
18+
// console.log(tellFortune(numChildren, partnerNames, locations, jobs));
19+
// console.log(tellFortune(numChildren, partnerNames, locations, jobs));
20+
// 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+
let shoppingCart = ['Banana', 'Milk'];
3+
4+
5+
function addToShoppingCart(groceryItem){
6+
shoppingCart.push(groceryItem);
7+
for (let i = 0; i < shoppingCart.length; i++){
8+
if (shoppingCart.length > 3){
9+
shoppingCart.shift();
10+
}
11+
};
12+
13+
return `You bought ${shoppingCart}`;
14+
};
15+
16+
17+
console.log(addToShoppingCart('chocolate'));
18+
console.log(addToShoppingCart('Fries'));
19+
console.log(addToShoppingCart('ananas'));
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
'use strict'
2+
const cartForParty = {
3+
beer: 4.99,
4+
chips : 1.99,
5+
cheese : 3.49,
6+
banana : 1.50,
7+
kiwi : 3.99
8+
}
9+
const totalPrice = (calculateObj) => {
10+
let total = 0;
11+
for (let item in calculateObj){
12+
total += calculateObj[item];
13+
}
14+
console.log(`total: € ${total}`)
15+
}
16+
totalPrice(cartForParty);
17+
18+
// now if we make any new object it will calculate the total price for it
19+
20+
const cartForluch ={
21+
meat : 4.99,
22+
chicken : 5.99,
23+
rise : 2.00,
24+
tomato : 1.99
25+
}
26+
totalPrice(cartForluch);
27+
28+
// that is cool
29+
30+
31+
32+
33+
34+
35+
//

0 commit comments

Comments
 (0)