hyf-javascript1's People
hyf-javascript1's Issues
Feedback homework week 3
Hi Rabia, here is my feedback on your JS1 week 3 homework.
There are some hints in your code that suggest to me that perhaps you still need to add some settings to your VSCode editor, specifically having to do with code formatting. Please check the VSCode Tips again and make sure the recommended settings are applied.
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. -
My favourite (not ๐) animal , the
meerkat
is supposed to come betweenblowfish
andcapricorn
, not where it is now. The rest is correct.
More JavaScript
-
Excellent that you chose the name
sum
for the function. That describes 100% what it does. -
You chose the name
colorCarVar
for the function parameter. Probably because the namecolorCar
was already taken by the function itself. However, theVar
suffix does not add meaning to the name, it is just there to make the name unique. It is rather a mouth full (try to say it quickly a number of times in a row ๐). I would go for the simpler namecolor
.By the way, excellent that you made your function pure, rather then using
console.log
directly in the function body. -
Correct.
-
Although your function looks correct, it is not executed. This is because you created a function with the same name in line 81, which overwrites the version of line 64. So the function call in line 69 actually calls the function of line 81.
Apart from that, excellent again that your function is pure. We can use its return value to log to the console or do something completely else. The suffix
Veh
ontypeVeh
does not add any useful meaning. We can already guess it is about the vehicle type from the fact that the function is about vehicles. I would just go for the nametype
.What I said half jokingly in step 2 above, pronounceable names are always preferred over cryptic names. Especially helpful if you want to discuss your code with somebody else over the telephone!
Excellent that you build up the string from the supplied parameters. Note that when you use the string concatenation operator
+=
you should not use another+
following it. And in the ternary operator you don't need the parentheses around the condition, although it is perfectly fine to do so if that makes it more clear to you:str += type === 1 ? ' car' : ' motorbike';
-
Correct.
-
Excellent.
ageVehicle
? ->age
will do just fine. -
If you just need to create an array of known vehicles, a simple array literal is cleaner:
const vehicles = ['car', 'motorbike', 'bike', 'caravan', 'boat', 'metro', 'train'];
-
You got the fourth element instead of the third element. Remember that array indices start at zero.
-
Here, you correctly changed the name of the function so that it does not conflict with an earlier version of that function. And you also correctly adjusted the index of the array to take into account that array indices start at zero.
-
As we discussed briefly in class, you need to use the plural form for each vehicle to make it correct English. See my solution for an alternative approach for this function.
-
Correct.
-
This is not an empty object but an empty array.
-
Again, this is not an object but an array.
-
Actually for the languages, we meant computer languages. If somebody taught you Chinese, you were in the wrong class!
-
The explanation that you give in step 16 also holds true for this step.
-
Your explanation is correct.
-
Correct
You have some extra code at the end of your file that is a bit puzzling:
y = parseInt(x);
console.log( typeof y);
The variable y
was declared at line 146, but reassigned here. Variable x
refers to an array (defined in line 146). The parseInt()
function expects a simple number as its argument. Anyway, this code does not seem to correspond to any assignment.
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.