/
assertEqual.js
100 lines (72 loc) · 2.49 KB
/
assertEqual.js
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
//CHALLENGE:
// FUNCTION IMPLEMENTATION
/*
INSTRUCTIONS:
https://developer.mozilla.org/en-US/docs/Web/API/console/assert
Make the function compare the two values it takes in
Print out a message telling us if they match or not.
*/
//Pseudocode:
//return a boolean, and tell if equivalent
//expect to get 2 arguments
//pass strings individually; 2 separate arguemnts for fn of actual and expected
const assertEqual = function(actual, expected) {
if (actual === expected) {
console.log("Assertion Passed: [actual] === [expected]")
return true;
} else { //else runs if is false
console.log("Assertion Failed: [actual] !== [expected]")
return false;
}
}
// TEST CODE
assertEqual("Lighthouse Labs", "Bootcamp"); //test if equivalent?
assertEqual(1, 1); //test if equivalanet?
/* CHALLENGE: IMPROVE assertEqual
Update our Lotide assertEqual function to use template literals when generating the output string.
This challenge assumes that you used + to concatenate values together for console.log.
//Pseudocode:
//Back ticks allow to interporlate variables into strings
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals
*/
const assertEqual = function(actual, expected) {
if (actual === expected) {
console.log(`Assertion Passed: ${actual} === ${expected}`)
return true;
} else { //else runs if is false
console.log(`Assertion Failed: ${actual} !== ${expected}`)
return false;
}
}
// TEST CODE
assertEqual("Lighthouse Labs", "Bootcamp"); //equal
assertEqual(1, 1); //equal
console.assert(assertEqual("Bootcamp", "Bootcamp"));
//EMOJIS:
const assertEqual = function(actual, expected) {
if (actual === expected) {
console.log(`Assertion Passed ❤: ${actual} === ${expected}`)
return true;
} else { //else runs if is false
console.log(`Assertion Failed :no_entry:: ${actual} !== ${expected}`)
return false;
}
};
// TEST CODE
assertEqual("Lighthouse Labs", "Bootcamp"); //equal
assertEqual(1, 1); //equal
console.assert(assertEqual("Bootcamp", "Bootcamp"));
/*
// FUNCTION IMPLEMENTATION
const assertEqual = function(actual, expected) {
//return actual === expected;
};
*/
/*
//QUESTION:
//Before you run the code written thus far in assertEqual.js, ask yourself: What is the expected output and why?
//ANSWER:
//no output if only left as is.
//Because we call the function but the function itself does nothing?
//Sure, but more specifically because we are not printing/logging anything to the console anywhere.
*/