hyf-javascript1's Issues
Feedback homework week 3
Hi Karam, here is my feedback on your JS1 week 3 homework.
Your code looks well formatted, with code blocks nicely separated with blank lines. There are a few missing semicolons, though.
Step 4: Strings and Array challenges
-
Excellent that you used the
.replace()
method in combination with 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. -
In line 12, the first argument should just be a number. What you have used is an array (because of the square brackets) of exactly one element. That element is the number
1
. The fact that is still produces the correct result is pure luck!Note: Avoid mixing up single and double quotes for delimiting strings. Choose one or the other and stick to that for all your code.
More JavaScript
-
The name you chose for this function does not accurately describe what it does. The name
sum
would be a natural name for this function. Always try to find names for your functions and variable that best describe what they do or represent.There is an extra comma after
c
in line 24 that should not be there.You don't need the parentheses that you used in the return statement. This will do:
return a + b + c
; -
When we say that a function receives some value, in this case a
color
, we mean that the function takes that as a parameter. So the function definition could look like this:coloredCar(color) { //... }
And you would use that
color
parameter to print the color inside the function. That also allows me to call your function with a different color, saygreen
and still get correct output. -
As in the previous step, your function should take the object as a parameter and then print out its content, for example:
function printObj(obj) { // ... } const myObj = { //... }; printObj(myObj);
In this way I can call your function with any object and get its content printed. As it stands now I always get your Nissan.
-
I think you got the
code
values mixed up. According to the assignment the 1 stands forcar
and 2 stands formotorbike
. -
Correct.
-
Although your function looks correct, it is not executed. This is because you created a function with the same name in step 9, which overwrites the version of step 6. So, in line 60 you are actually calling the function of step 9, which produces the output
a Blue Motorbike
rather thana Blue Used car
. You can avoid this issue by renaming the function of step 9 to, say,vehicle2
. Or you can put each exercise in a block scope as I have done in my solution of the homework. -
You created an array of objects, which if fine too, but for the exercises here you could have just created an array of strings, like you did in your alternative
vehicles0
.Note that in English, to form a plural, you do not use an apostrophe between the word and the final
s
, for example:motorbikes
etc. -
Correct.
-
Your function should use the
code
parameter to determine the type of vehicle to print out. In your version you have assumed that it is always abike
. -
(+11) Your code assumes that the last vehicle in the list is always
cars
. But there is nocar
in your vehicle list array. -
I don't see a new advertisement output with the
boat
added. -
Correct,
-
Okay.
-
Fine. But you could have use
console.log
to check the result. -
You could add a comment in which you describe what is actually happening.
-
Same as above.
-
Correct.
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.