forked from HackYourFuture/Assignments
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathex3-tellFortune.js
More file actions
30 lines (22 loc) · 1.01 KB
/
ex3-tellFortune.js
File metadata and controls
30 lines (22 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
function selectRandomly(choices) {
return choices[Math.floor(Math.random() * choices.length)];
}
export function tellFortune(childrenArr, partnersArr, locationsArr, jobsArr) {
const numKids = selectRandomly(childrenArr);
const partnerName = selectRandomly(partnersArr);
const location = selectRandomly(locationsArr);
const jobTitle = selectRandomly(jobsArr);
return `You will be a ${jobTitle} in ${location}, married to ${partnerName} with ${numKids} kids.`;
}
function main() {
const numKids = [2, 4, 1, 7, 5];
const partnerNames = ['Yusuf', 'Leen', 'Sarah', 'Eliana', 'Amal'];
const locations = ['Amsterdam', 'Breda', 'Tilburg', 'Utrecht', 'Rotterdam'];
const jobTitles = ['Programmer', 'Teacher', 'Soldier', 'Manager', 'Musician'];
console.log(tellFortune(numKids, partnerNames, locations, jobTitles));
console.log(tellFortune(numKids, partnerNames, locations, jobTitles));
console.log(tellFortune(numKids, partnerNames, locations, jobTitles));
}
if (process.env.NODE_ENV !== 'test') {
main();
}