This repository was archived by the owner on Jan 14, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 476
Expand file tree
/
Copy path3-function-output.js
More file actions
42 lines (33 loc) · 1.88 KB
/
3-function-output.js
File metadata and controls
42 lines (33 loc) · 1.88 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
// Add comments to explain what this function does. You're meant to use Google!
function getRandomNumber() {
return Math.random() * 10;
}
/* The Math.random() function returns a floating-point, pseudo-random number that's greater than or equal to 0 and less than 1, with approximately uniform distribution over that range — which you can then scale to your desired range. The implementation selects the initial seed to the random number generation algorithm; it cannot be chosen or reset by the user. */
// Add comments to explain what this function does. You're meant to use Google!
function combine2Words(word1, word2) {
return word1.concat(word2);
}
/* The concat() method is used to merge two or more arrays. This method does not change the existing arrays, but instead returns a new array. */
function concatenate(firstWord, secondWord, thirdWord) {
// Write the body of this function to concatenate three words together.
// Look at the test case below to understand what this function is expected to return.
// return firstWord.concat(secondWord).concat(thirdWord);
return `${firstWord} ${secondWord} ${thirdWord}`;
}
/*
===================================================
======= TESTS - DO NOT MODIFY BELOW THIS LINE =====
There are some Tests in this file that will help you work out if your code is working.
To run the tests for just this one file, type `npm test -- --testPathPattern 3-function-output` into your terminal
(Reminder: You must have run `npm install` one time before this will work!)
==================================
*/
test("concatenate example #1", () => {
expect(concatenate("code", "your", "future")).toEqual("code your future");
});
test("concatenate example #2", () => {
expect(concatenate("I", "like", "pizza")).toEqual("I like pizza");
});
test("concatenate doesn't only accept strings", () => {
expect(concatenate("I", "am", 13)).toEqual("I am 13");
});