Homework JavaScript 1
zmagzoub / hyf-javascript1 Goto Github PK
View Code? Open in Web Editor NEWHomework JavaScript 1
Homework JavaScript 1
Hi Zaed, here is my feedback on your homework.
Your code is correct, it produces the correct results. Nice work! Please pay attention to the following points.
1. Your code is in some places not indented in a standard way. That indicates to me that you didn't set the VSCode settings correctly. We did this in class last Sunday, but somehow you seem to have missed it. Please check again the VSCode Tips for these settings.
2. You are missing a semicolon in line 4 of 1-strings.js
. ESLint issued a warning for this (did you see the green wavy underline?) There is also one missing in 2-arrays.js
.
3. In line 15 of 2-arrays.js
, where you are looking for the index of meerkat
, it would be better to save that index into a variable. The reason for that is because you are trying delete meerkat
from the array in line 16. You should not "hard code" the number 1, but instead use the value you found earlier. Then you can easily deal with the situation of the index of meerkat
being changed, e.g. because something was inserted, or that meerkat
was deleted by some other code. In the latter case the index would be -1, indicating that nothing was found.
Example:
const meerkatIndex = favoriteAnimals.indexOf('meerkat');
console.log('Item to be deleted is at index: ' + meerkatIndex);
if (meerkatIndex !== -1) {
favoriteAnimals.splice(meerkatIndex, 1);
}
console.log(favoriteAnimals);
Hi Zaed, here is my feedback on your homework for week 3.
Overall, you've done pretty well. Try and make your functions pure and without side effects as much as you can.
Excellent!
ESLint warns that myCar
could be declared with const
. The latter is preferred over let
if the variable is not reassigned. In general, const
should 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 to let
.
Be consistent in your use of upper and lower case.
a Black car -> a black car, or, A black car.
for...in
. You can also use Object.keys()
and use a regular for
loop or a for...of
loop. Note that property
can be a const
as ESLint indicates. In general, you should follow up on all issues identified by ESLint. That's the whole point of ESLint: to give you warnings and errors where your code can (and should) be improved.You seem to have missed this instruction from the assignment:
Your function should return a string, ...
In general, you should strive to make your functions pure and without any side effects. This makes your functions reusable and easy to test. In this case, don't use console.log
in your function. Instead, use console.log
to print the return value of your function, like you did for instance in more01
and more02
.
I had expected 'a yellow unknown vehicle'
for the third call, but I guess the assignment is not totally clear on that.
Excellent!
console.log
inside your function. See the comment for more04.js
.car
?This looks very much like a math relation:
if ((0 < code) && (code <= vehicles.length)) {
// 0 < code <= vehicles.length
Most developers would write this as:
if (code > 0 && code <= vehicles.length) {
You don't need the extra parentheses because the logical operator &&
is of lower precedence than the comparison operators. However, they don't do harm either.
In this exercise, I would move the vehicles
constant inside the function body and move the console.log
out of it. This again makes the function pure and without side effects.
for
loop (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.const
where ESLint gives you warnings about using let
.x
and y
are like twin brothers, they look the same but are separate entities. However, z
is just another name for x
.'use strict';
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.