Skip to content

Commit 83925c3

Browse files
committed
added 3a and 3b
1 parent 300e98f commit 83925c3

3 files changed

Lines changed: 54 additions & 8 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
node_modules/
2+
answers.txt

___tests___/destructuring.test.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { name, quantity, price, one, two, three, four, five, six } = require('../destructuring.js')
1+
const { name, quantity, price, one, two, three, four, five, six, johnName, johnAge, isJohnAdmin, steveName, steveAge, isSteveAdmin } = require('../destructuring.js')
22

33
describe('array destructuring instead of assigning each value to a variable', () => {
44
it('check name price and quantity is set correctly', () => {
@@ -9,7 +9,7 @@ describe('array destructuring instead of assigning each value to a variable', ()
99
})
1010

1111
describe('assigning names to variables', () => {
12-
it('check values have been correctly assigned', () => {
12+
xit('check values have been correctly assigned', () => {
1313
expect(one).toBe(1)
1414
expect(two).toBe(2)
1515
expect(three).toBe(3)
@@ -18,3 +18,17 @@ describe('assigning names to variables', () => {
1818
expect(six).toBe(6)
1919
})
2020
})
21+
22+
describe('destructuring and default values', () => {
23+
xit('check values of destructuring john object', () => {
24+
expect(johnName).toBe('John')
25+
expect(johnAge).toBe(30)
26+
expect(isJohnAdmin).toBe(true)
27+
})
28+
29+
xit('check default value from destructuring steve object', () => {
30+
expect(steveName).toBe('Steve')
31+
expect(steveAge).toBe(25)
32+
expect(isSteveAdmin).toBe(false)
33+
})
34+
})

destructuring.js

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ let quantity = item[2];
1616

1717
// Change above this line
1818

19+
// ---------------------------------------------------------------------
20+
1921
/*
2022
Exercise 2
2123
@@ -31,17 +33,46 @@ let [one, two, three, four, five, six] = numbers;
3133

3234
// Change above this line
3335

36+
// ---------------------------------------------------------------------
37+
3438
/**
35-
Exercise 3
39+
Exercise 3a
3640
37-
We have an object called 'user'.
41+
We have an object called 'john'.
3842
Write the destructuring assignment that reads:
39-
- 'name' property into the variable 'name'.
40-
- 'years' property into the variable 'age'.
41-
- 'isAdmin' property into the variable 'isAdmin' (false, if no such property)
43+
- 'name' property into the variable 'johnName'.
44+
- 'years' property into the variable 'johnAge'.
45+
- 'isAdmin' property into the variable 'isJohnAdmin'
4246
*/
4347

48+
let john = { name: "John", years: 30, isAdmin: true };
49+
50+
// Change below this line
51+
52+
let johnName = john.name
53+
let johnAge = john.years
54+
let isJohnAdmin = john.isAdmin
55+
56+
// Change above this line
57+
4458

59+
// Exercise 3b
60+
61+
// We have an object called 'steve'. Similiar as before
62+
// 'name' property into the variable 'steveName'.
63+
// - 'years' property into the variable 'steveAge'.
64+
// - 'isAdmin' property into the variable 'isSteveAdmin' (false, if no such property)
65+
66+
let steve = { name: "Steve", years: 25 };
67+
68+
// Change below this line
69+
70+
let steveName = steve.name
71+
let steveAge = steve.years
72+
let isSteveAdmin = steve.isAdmin
73+
74+
// Change above this line
4575

76+
// ---------------------------------------------------------------------
4677

47-
module.exports = { name, quantity, price, one, two, three, four, five, six }
78+
module.exports = { name, quantity, price, one, two, three, four, five, six, johnName, johnAge, isJohnAdmin, steveName, steveAge, isSteveAdmin }

0 commit comments

Comments
 (0)