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 477
Expand file tree
/
Copy path2-logic-error.js
More file actions
50 lines (38 loc) · 1.43 KB
/
2-logic-error.js
File metadata and controls
50 lines (38 loc) · 1.43 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
// The syntax for these functions is valid but there are some errors, find them and fix them
function trimWord(word) {
return word.trim();
}
function getStringLength(word) {
return word.length;
}
function multiply(a, b, c) {
return a * b * c;
}
/*
===================================================
======= 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 2-logic-error` into your terminal
(Reminder: You must have run `npm install` one time before this will work!)
===================================================
*/
test("trimWord trims leading and trailing whitespace", () => {
expect(trimWord(" CodeYourFuture ")).toEqual("CodeYourFuture");
});
test("trimWord doesn't remove whitespace in the middle of the string", () => {
expect(trimWord(" CodeYourFuture teaches coding ")).toEqual(
"CodeYourFuture teaches coding"
);
});
test("getStringLength returns the length of a word", () => {
expect(getStringLength("Turtles")).toEqual(7);
});
test("getStringLength returns the length of a sentence", () => {
expect(getStringLength("A wild sentence appeared!")).toEqual(25);
});
test("multiply multiplies numbers", () => {
expect(multiply(2, 3, 6)).toEqual(36);
});
test("multiply multiplies different numbers", () => {
expect(multiply(2, 3, 4)).toEqual(24);
});