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 258
Expand file tree
/
Copy pathexercise.js
More file actions
47 lines (35 loc) · 1.11 KB
/
exercise.js
File metadata and controls
47 lines (35 loc) · 1.11 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
/*
You are given a sentence contains a story.
Current it says
"I like dogs. One day I went to the park and I saw 10 dogs. It was a great day."
Change the story using .replace() so that it says
"I like cats. One night I went to the park and I saw 100000 cats. It was a brilliant night."
*/
let story =
"I like dogs. One day I went to the park and I saw 10 dogs. It was a great day.";
let result = story.replace("dogs");
console.log(result);
/* EXPECTED OUTPUT */
const util = require("util");
function test(test_name, actual, expected) {
console.log("");
let status;
if (actual === expected) {
status = "PASSED";
} else {
status = `FAILED: \nexpected: ${util.inspect(
expected
)} \nbut your function returned: ${util.inspect(actual)}`;
}
console.log(`${test_name}: ${status}`);
}
test(
"1. Original story has not been changed",
story,
"I like dogs. One day I went to the park and I saw 10 dogs. It was a great day."
);
test(
"2. The result of the replace is correct",
result,
"I like cats. One night I went to the park and I saw 100000 cats. It was a brilliant night."
);