forked from HackYourFuture/Assignments
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathex4-shoppingCart.js
More file actions
57 lines (49 loc) · 1.47 KB
/
ex4-shoppingCart.js
File metadata and controls
57 lines (49 loc) · 1.47 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
52
53
54
55
56
57
const shoppingCart = ['bananas', 'milk'];
function addToShoppingCart(item) {
shoppingCart.push(item);
if (shoppingCart.length > 3) {
shoppingCart.shift();
}
const shoppingCartItems = shoppingCart.join(', ');
return `You bought ${shoppingCartItems}!`;
}
function test1() {
console.log(
'Test 1: addShoppingCart() called without an argument should leave the shopping cart unchanged'
);
const expected = 'You bought bananas, milk!';
const actual = addToShoppingCart();
console.assert(actual === expected);
}
function test2() {
console.log('Test 2: addShoppingCart() should take one parameter');
const expected = 1;
const actual = addToShoppingCart.length;
console.assert(actual === expected);
}
function test3() {
console.log('Test 3: `chocolate` should be added');
const expected = 'You bought bananas, milk, chocolate!';
const actual = addToShoppingCart('chocolate');
console.assert(actual === expected);
}
function test4() {
console.log('Test 4: `waffles` should be added and `bananas` removed');
const expected = 'You bought milk, chocolate, waffles!';
const actual = addToShoppingCart('waffles');
console.assert(actual === expected);
}
function test5() {
console.log('Test 5: `tea` should be added and `milk` removed');
const expected = 'You bought chocolate, waffles, tea!';
const actual = addToShoppingCart('tea');
console.assert(actual === expected);
}
function test() {
test1();
test2();
test3();
test4();
test5();
}
test();