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