-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Hi Wouter, here is my feedback on your homework for week 3.
I think you did pretty well. The advertisement assignment has been a challenge for all previous classes, so no worries there.
1-more.js
- Remove the blank line in line 5. Use blank lines to separate blocks of related code, like you would use a blank line to separate paragraphs in a piece of written text. Remove blank lines for which you have no clear explanation.
2-more.js
- Remove blank line 5.
- Be consistent in how you use quotes. Either all single quotes (my preference) or all double quotes. (This goes for all exercises, so I won't repeat it any more).
3-more.js
Excellent!
4-more.js
- I had expected
'a red unknown vehicle'for the third call, but I guess the assignment is not totally clear on that.
5-more.js
Excellent!
6-more.js
- ESLint gives a warning that
conditionon line 6 could be aconst. The latter is preferred overletif the variable is not reassigned. In general,constshould be your first choice as it gives the best protection against inadvertent modification. Only where you find that you need to change the variable somewhere else you should revert tolet.
7-more.js
-
Excellent use of an array to avoid a chain of
if...elsestatements for thetypeOfWheels. -
I would not include a space in the vehicle names. The space is needed for presentation purposes, it is not part of the data. Therefore, include the space at the point of presentation. (Same goes for "new" and "used".) This recommendation is an application of the principle of Separation of Concerns.
const typeOfWheels = ["car", "motorbike", "caravan", "bike"]; // <== data result = "a " + color + condition + " " + typeOfWheels[type]; // <== presentation
8-more.js, 9-more.js
- Whenever you need to work on an array you probably need some form of
forloop (or, as you will learn in JS2 week 2, array methods). With an array you should not make assumptions about its length, and you should not access array elements with hard-coded numeric array indices. Your code should work with an array of zero or more elements. I think Tamim did this exercise in class, so I won't cover it further here.
10-more.js
-
When you run the code you will see that only the array element with the last index listed gets the language assigned to it:
ourWonderfulTeachers[0, 1].languages = ["JavaScript"]; // <== only Rohan gets assigned this language
Check MDN Comma Operator for an explanation.
11-more.js
- To use a metaphor:
xandyare like twin brothers, they look the same but are separate entities. However,zis just another name forx.
12-more.js
- Yep
13-more.js
- The
typeofreturns the type of a value as a string, e.g.'number','string','object'etc. Thetypeofof the value returned bytypeofis therefore a'string'.