This repository was archived by the owner on Oct 26, 2020. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy path2-bush-berries.js
More file actions
51 lines (39 loc) · 1.36 KB
/
2-bush-berries.js
File metadata and controls
51 lines (39 loc) · 1.36 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
/*
The space travellers have safely landed and are foraging for food in the natural wildlife.
There are bushes with many different colour berries.
The pink berries are the ONLY safe ones to eat.
If any other berries are present, it's best not to eat from the bush at all!
Create a function which checks if the bush has ALL PINK berries and is safe for the astronauts to eat from the bush.
Use the tests to confirm which message to return
*/
function bushChecker(arr) {
let safeToEat = arr.every(item => item === 'pink');
if(safeToEat === true){
return "Bush is safe to eat from";
}else{
return "Toxic! Leave bush alone!";
}
}
/* ======= TESTS - DO NOT MODIFY ===== */
let bushBerryColours1 = ["pink", "pink", "pink", "neon", "pink", "transparent"]
let bushBerryColours2 = ["pink", "pink", "pink", "pink"]
const util = require('util');
function test(test_name, actual, expected) {
let status;
if (actual === expected) {
status = "PASSED";
} else {
status = `FAILED: expected: ${util.inspect(expected)} but your function returned: ${util.inspect(actual)}`;
}
console.log(`${test_name}: ${status}`);
}
test(
"bushChecker funtion works - case 1",
bushChecker(bushBerryColours1),
"Toxic! Leave bush alone!"
);
test(
"bushChecker funtion works - case 1",
bushChecker(bushBerryColours2),
"Bush is safe to eat from"
);