hyf-javascript1's People
hyf-javascript1's Issues
Feedback homework week 3
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 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:if (type === 1) { type = 'car'; } else { type = 'motorbike'; }
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
:let vehicle = 'motorbike'; if (type === 1) { vehicle = 'car'; }
Or, using the ternary operator:
const vehicle = (type === 1) ? 'car' : 'motorbike';
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:
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 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:
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 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?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.