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
Hi Joudi, here is my feedback on your JS1 week 3 homework.
I can see that you had some fun with experimenting with some assignments, however there are also some things that you need to look at.
Step 4: Strings and Array challenges
You are the first one to offer two rather than one solution to this. Both are fine. Most developers would probably go for the second solution, using a regular expression. We won't cover regular expressions in the lectures as it is an advanced, vast topic but at least you got a taste of it here.
Looks pretty good.
A minor point: the idea for 2.4 was that you put in words what you thought the actual values would be rather than printing the actual values:
console.log("I think my new array will have the values: blowfish, meerkat, capricorn, giraffe, turtle")
More JavaScript
Your idea of using alert and prompt is a nice idea, however it makes running and checking your code more difficult. I have to look in two places (the web page and the console) and remember or makes notes of what I typed as input in order to check the output. So again, nice idea, but for reviewing purposes I would prefer function calls with fixed parameters.
You probably commented out the code in your initial pull request because of the alerts and the prompts hindering testing.
Correct. But you do not need to use (and preferably should not use) parentheses around the value in a return statement. This holds true for all other steps in this file.
Excellent that you use parseInt() to convert the text that the user typed in the prompt() into a number, because prompt() itself returns a string. I guess you tried it first without parseInt() and saw that something completely different happened, right?
The parameter that you pass to your colorCar() function is called color but you do not use this parameter inside the function body. Instead you are grabbing the external variable myFavoriteColor as the value to use. This makes your function impure and the color parameter redundant.
Your function is called displayObject() but that is not what it does: it simply returns the value of its argument without displaying anything. If you would place the console.log statement inside the function body thrn it would do at its name implies.
The use of Object.entries is a clever find. You could also you a for loop.
A good idea to make your vehicleType() functions unique by adding the assignment number to the function name. This avoids issues with defining functions with the same name in a single file.
Excellent that you made this a pure function and use console.log outside of the function.
You should always use the strict equality operator, i.e. the one with the triple equal signs: ===.
It is a best practice to format an if statement in a standard way:
Note that reassigning parameters to a new value inside the function body is considered a bad practice. You are doing that here with the type parameter. First it was a number, indicating a code for a vehicle type and then it becomes a string representing a vehicle name. Instead, you could introduce a new variable, say vehicle:
Because the assignment is done in a single statement you can use const here.
Correct.
The same comment from step 4 applies here too: don't reassign parameters inside the function body. Also do not change the value type that a variable holds: age was a number and now becomes a description of the car condition (new vs used). This can easily lead to confusion what a parameter represents once your code starts to grow.
Correct.
Correct.
The assignment specifies that you should be able to call your function like this:
vehicle("green",3,1)// console.log(vehicle("green", 3, 1)) is fine too
Clearly your function does not meet this requirement. The code parameter should be used as an index into your vehicles array, taking into account that JavaScript array indices are zero-based.
Correct. Note that the choice for 'bus' in this assignment is best avoided because the plural of 'bus' is 'buses' and not 'buss'.
The idea was that you printed a new advertisement with an extra vehicle added to the array. That would have been easy if you implemented step 10 as a function that you call twice.
Correct. Nice that you used const.
Okay.
You should use dot notation where you can when accessing object properties, in preference over bracket notation. Also, object property names should be in camelCase:
teachers.languages= ...
I think you were a bit careless with copy & paste here because all tests are about x == y. You also need to watch out for operator precedence. What does this do?
'x==y is'+x==y ? 'equal' : 'not equal'
Are you concatenating x to the string 'x==y is' and then comparing that with y using ==?
Or are you comparing x and y and then concatenating 'equal' or 'unequal' to 'x==y is'?
By adding some parentheses you can eliminate the confusion.
What is your conclusion? Can you describe that in a comment?
What is happening here? Can you describe that in a comment?
The text was updated successfully, but these errors were encountered:
Hi Joudi, here is my feedback on your JS1 week 3 homework.
I can see that you had some fun with experimenting with some assignments, however there are also some things that you need to look at.
Step 4: Strings and Array challenges
You are the first one to offer two rather than one solution to this. Both are fine. Most developers would probably go for the second solution, using a regular expression. We won't cover regular expressions in the lectures as it is an advanced, vast topic but at least you got a taste of it here.
Looks pretty good.
A minor point: the idea for 2.4 was that you put in words what you thought the actual values would be rather than printing the actual values:
More JavaScript
Your idea of using
alert
andprompt
is a nice idea, however it makes running and checking your code more difficult. I have to look in two places (the web page and the console) and remember or makes notes of what I typed as input in order to check the output. So again, nice idea, but for reviewing purposes I would prefer function calls with fixed parameters.You probably commented out the code in your initial pull request because of the alerts and the prompts hindering testing.
Correct. But you do not need to use (and preferably should not use) parentheses around the value in a
return
statement. This holds true for all other steps in this file.Excellent that you use
parseInt()
to convert the text that the user typed in theprompt()
into a number, becauseprompt()
itself returns a string. I guess you tried it first withoutparseInt()
and saw that something completely different happened, right?The parameter that you pass to your
colorCar()
function is calledcolor
but you do not use this parameter inside the function body. Instead you are grabbing the external variablemyFavoriteColor
as the value to use. This makes your function impure and thecolor
parameter redundant.Your function is called
displayObject()
but that is not what it does: it simply returns the value of its argument without displaying anything. If you would place theconsole.log
statement inside the function body thrn it would do at its name implies.The use of
Object.entries
is a clever find. You could also you afor
loop.A good idea to make your
vehicleType()
functions unique by adding the assignment number to the function name. This avoids issues with defining functions with the same name in a single file.Excellent that you made this a pure function and use
console.log
outside of the function.You should always use the strict equality operator, i.e. the one with the triple equal signs:
===
.It is a best practice to format an
if
statement in a standard way:See Code Formatting in the HYF fundamentals repo.
Note that reassigning parameters to a new value inside the function body is considered a bad practice. You are doing that here with the
type
parameter. First it was a number, indicating a code for a vehicle type and then it becomes a string representing a vehicle name. Instead, you could introduce a new variable, sayvehicle
:Or, using the ternary operator:
Because the assignment is done in a single statement you can use
const
here.Correct.
The same comment from step 4 applies here too: don't reassign parameters inside the function body. Also do not change the value type that a variable holds:
age
was a number and now becomes a description of the car condition (new
vsused
). This can easily lead to confusion what a parameter represents once your code starts to grow.Correct.
Correct.
The assignment specifies that you should be able to call your function like this:
Clearly your function does not meet this requirement. The
code
parameter should be used as an index into yourvehicles
array, taking into account that JavaScript array indices are zero-based.Correct. Note that the choice for
'bus'
in this assignment is best avoided because the plural of'bus'
is'buses'
and not'buss'
.The idea was that you printed a new advertisement with an extra vehicle added to the array. That would have been easy if you implemented step 10 as a function that you call twice.
Correct. Nice that you used
const
.Okay.
You should use dot notation where you can when accessing object properties, in preference over bracket notation. Also, object property names should be in camelCase:
I think you were a bit careless with copy & paste here because all tests are about
x == y
. You also need to watch out for operator precedence. What does this do?Are you concatenating
x
to the string'x==y is'
and then comparing that withy
using==
?Or are you comparing
x
andy
and then concatenating'equal'
or'unequal'
to'x==y is'
?By adding some parentheses you can eliminate the confusion.
What is your conclusion? Can you describe that in a comment?
What is happening here? Can you describe that in a comment?
The text was updated successfully, but these errors were encountered: