|
| 1 | +'use strict' |
| 2 | + |
| 3 | +/* |
| 4 | + description exercise with array parameters & rng |
| 5 | +*/ |
| 6 | + |
| 7 | +function runExercise03 () { |
| 8 | + console.log("= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = ="); |
| 9 | + console.log("JS-1 - week 3 - Exercise 03 - Fortune teller"); |
| 10 | + console.log("Array parameters & random element selection"); |
| 11 | + console.log("- - - - - - - - - - - - - - - - - - - -"); |
| 12 | + function tellFortune(listJobs,listCities,listSpouceNames,listChildren){ |
| 13 | + function spliceRandomValue(anArray){ |
| 14 | + return anArray.splice(Math.floor(Math.random()*anArray.length),1)}; |
| 15 | + function addPrefix(paramValue){ |
| 16 | + return ('aeioy'.indexOf(paramValue.toString()[0].toLowerCase())<0?"a ":"an ")+paramValue}; |
| 17 | + let childNum=spliceRandomValue(listChildren); |
| 18 | + let childrenText=(childNum<1?"without children":"with " |
| 19 | + +(childNum==1?"one child":`${childNum} kids`)); |
| 20 | + return `You will be ${addPrefix(spliceRandomValue(listJobs))}` |
| 21 | + +` living in ${spliceRandomValue(listCities)}` |
| 22 | + +`, married to ${addPrefix(spliceRandomValue(listJobs))}` |
| 23 | + +` named ${spliceRandomValue(listSpouceNames)} ${childrenText}.`; |
| 24 | + } |
| 25 | + let funnyJobsList=['Chocolate Beer Wrestler Administrator','Cat Editor Behavior Consultant' |
| 26 | + ,'Unicorn Division Chief Farmer','Belly Dance Ninja Poet' |
| 27 | + ,'Bride Kidnapping Master Carpenter','Web Snake Developer-Milker' |
| 28 | + ,'Sub-Commitment Under-Secretary','Master Handshake Broker' |
| 29 | + ,'Water Slide Toast Tester','Professional Sleeper Pilot' |
| 30 | + ,'Inspiration Office Rider','Beverage Dissemination Officer Agent' |
| 31 | + ,'Digital Prophet Boxer','Galactic Research Viceroy of Excellence' |
| 32 | + ,'Space Travel Agent-Burglar','Chief Troublemaker Commando' |
| 33 | + ,'In-house Zoologist-Philosopher','Shadow Accounting Dancer' |
| 34 | + ,'Electrician-Gynecologist','Computer Speech Accountant' |
| 35 | + ,'Occupational Hazard Engineer','Hunter-Seeker Epidemiologist']; |
| 36 | + let locationNames=['Dublin','Bruges','Porto','Berlin','Zagre','Marseille','Stockholm' |
| 37 | + ,'Athens','Oslo','Bratislava','Frankfurt','Amsterdam']; |
| 38 | + let partnerNames=['Luisa','Gema','Sandra','Alba','Ariadne','Rosa' |
| 39 | + ,'Rebeca','Sonia','Kate','Nastasje','Eva']; |
| 40 | + let numChildren=[0,1,2,3,0,1,2,3,0,1,2,1]; |
| 41 | + for (let i=0; i<10; i++) |
| 42 | + {console.log(tellFortune(funnyJobsList,locationNames,partnerNames,numChildren))}; |
| 43 | + console.log("= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = ="); |
| 44 | + console.log(" "); |
| 45 | +}; |
| 46 | + |
| 47 | +runExercise03(); |
| 48 | + |
0 commit comments