You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 99e811b
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: Sprint-2/debug/address.js
+1-14Lines changed: 1 addition & 14 deletions
Original file line number
Diff line number
Diff line change
@@ -4,19 +4,6 @@
4
4
// but it isn't working...
5
5
// Fix anything that isn't working
6
6
7
-
/*const address = {
8
-
houseNumber: 42,
9
-
street: "Imaginary Road",
10
-
city: "Manchester",
11
-
country: "England",
12
-
postcode: "XYZ 123",
13
-
};
14
-
15
-
console.log(`My house number is ${address[0]}`); */
16
-
17
-
// The line "address[0]" is wrong. Because address is an object not an array, so "address[0]" is undefined. The output will be "My house number is undefined".
18
-
19
-
// Corrected code
20
7
constaddress={
21
8
houseNumber: 42,
22
9
street: "Imaginary Road",
@@ -25,4 +12,4 @@ const address = {
25
12
postcode: "XYZ 123",
26
13
};
27
14
28
-
console.log(`My house number is ${address.houseNumber}`);
Copy file name to clipboardExpand all lines: Sprint-2/debug/author.js
+1-19Lines changed: 1 addition & 19 deletions
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,7 @@
3
3
// This program attempts to log out all the property values in the object.
4
4
// But it isn't working. Explain why first and then fix the problem
5
5
6
-
/* const author = {
6
+
constauthor={
7
7
firstName: "Zadie",
8
8
lastName: "Smith",
9
9
occupation: "writer",
@@ -14,21 +14,3 @@
14
14
for(constvalueofauthor){
15
15
console.log(value);
16
16
}
17
-
*/
18
-
19
-
// Prediction and Explanation
20
-
/* The line "for (const value of author) {console.log(value);}" will not work because for-of is used only for iterable things, e.g: arrays, strings, maps, sets.
21
-
But author is a plain object (created with {}), and plain objects are not iterable. So Javascript throws: TypeError: author is not iterable because objects don't have a natural order to loop through. */
The line inside the template string: ${recipe} does not print the ingredients.
21
-
Instead, JavaScript converts the entire recipe object into a string, which becomes "[object Object]". This happens
22
-
because plain objects {} are not automatically converted into readable text. The program should print each ingredient on a new line, but the current code
23
-
never loops through recipe.ingredients, so nothing is printed correctly.
Copy file name to clipboardExpand all lines: Sprint-2/interpret/invert.js
+5-21Lines changed: 5 additions & 21 deletions
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@
5
5
// Then it should swap the keys and values in the object
6
6
7
7
// E.g. invert({x : 10, y : 20}), target output: {"10": "x", "20": "y"}
8
-
/*
8
+
9
9
functioninvert(obj){
10
10
constinvertedObj={};
11
11
@@ -15,31 +15,15 @@ function invert(obj) {
15
15
16
16
returninvertedObj;
17
17
}
18
-
*/
19
18
20
-
// a) What is the current return value when invert is called with { a : 1 } - The current return value is { key: 1}
19
+
// a) What is the current return value when invert is called with { a : 1 }
21
20
22
-
// b) What is the current return value when invert is called with { a: 1, b: 2 } - The current return value is { key: 2}
21
+
// b) What is the current return value when invert is called with { a: 1, b: 2 }
23
22
24
-
// c) What is the target return value when invert is called with {a : 1, b: 2} - The target return value is { "1": "a", "2": "b" }
23
+
// c) What is the target return value when invert is called with {a : 1, b: 2}
25
24
26
25
// c) What does Object.entries return? Why is it needed in this program?
27
-
/* Object.entries(obj) returns an array of [key, value] pairs. Example: Object.entries({ a:1, b:2 }) returns [["a", 1], ["b", 2]].
28
-
It is needed because the loop "for (const [key, value] of Object.entries(obj))" let's each pair destructure easily.
29
-
*/
30
26
31
-
// d) Explain why the current return value is different from the target output - It is because this line "invertedObj.key = value;" uses literal string "key instead of the variable key" which is a wrong property name,
32
-
// instead of this "invertedObj[value] = key;"
27
+
// d) Explain why the current return value is different from the target output
33
28
34
29
// e) Fix the implementation of invert (and write tests to prove it's fixed!)
0 commit comments