Skip to content

Commit 0f3feea

Browse files
committed
tobenot
1 parent 6e08fb7 commit 0f3feea

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

Programs/Exercise/tobenot.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
2+
/*
3+
4+
Write a function expect that helps developers test their code.
5+
It should take in any value val and return an object with the following two functions.
6+
7+
toBe(val) accepts another value and returns true if the two values === each other.
8+
If they are not equal, it should throw an error "Not Equal".
9+
10+
11+
notToBe(val) accepts another value and returns true if the two values !== each other.
12+
If they are equal, it should throw an error "Equal".
13+
14+
15+
Example 1:
16+
17+
Input: func = () => expect(5).toBe(5)
18+
Output: {"value": true}
19+
Explana
20+
*/
21+
22+
23+
var expect = function (val) {
24+
25+
// return an object
26+
return {
27+
//first funtion
28+
toBe: (value) => {
29+
30+
if (value === val) {
31+
return true
32+
} else {
33+
34+
throw "Not Equal"
35+
}
36+
},
37+
38+
//second funtion
39+
notToBe: (value) => {
40+
if (value !== val) {
41+
return true
42+
} else {
43+
throw "Equal"
44+
}
45+
46+
}
47+
48+
}
49+
};
50+
51+
console.log(expect(5).toBe(5)); // true
52+
expect(5).toBe(10); // throws "Not Equal"

0 commit comments

Comments
 (0)