forked from HackYourFuture/Assignments
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathex1-giveCompliment.js
More file actions
57 lines (47 loc) · 1.94 KB
/
ex1-giveCompliment.js
File metadata and controls
57 lines (47 loc) · 1.94 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/* -----------------------------------------------------------------------------
Full description at: https://github.com/HackYourFuture/Assignments/tree/main/1-JavaScript/Week3#exercise-1-you-are-amazing
1. Complete the function named `giveCompliment`as follows:
- It should take a single parameter: `name`.
- Its function body should include a variable that holds an array,
`compliments`, initialized with 10 strings. Each string should be a
compliment, like `"great"`, `"awesome"` and so on.
- It should randomly select a compliment from the array.
- It should return the string "You are `compliment`, `name`!", where
`compliment` is a randomly selected compliment and `name` is the name that
was passed as an argument to the function.
2. Call the function three times, giving each function call the same argument:
your name.
Use `console.log` each time to display the return value of the
`giveCompliment` function to the console.
-----------------------------------------------------------------------------*/
export function giveCompliment(name) {
const compliments = [
'doing great',
'beautiful',
'doing a fantastic job',
'strong',
'more prepared than you feel',
'quite smart',
'making amazing progress',
'smart',
'growing stronger with every step',
'becoming a better developer every day',
]
const randomIndex = Math.floor(Math.random() * compliments.length)
const randomCompliment = compliments[randomIndex]
return `You are ${randomCompliment}, ${name}!`;
}
function main() {
const myName = 'HackYourFuture';
console.log(giveCompliment(myName));
console.log(giveCompliment(myName));
console.log(giveCompliment(myName));
const yourName = 'Amsterdam';
console.log(giveCompliment(yourName));
console.log(giveCompliment(yourName));
console.log(giveCompliment(yourName));
}
// ! Do not change or remove the code below
if (process.env.NODE_ENV !== 'test') {
main();
}