allouhm / hyf-javascript1 Goto Github PK
View Code? Open in Web Editor NEWHomework Javascript1
Homework Javascript1
Hi Mahmoud, here is my feedback on your homework for week 3.
Correct!
Correct! Some minor issues:
Correct!
It seems you have overlooked this in the assignment:
Your function should return a string ...
By placing console.log
statements inside the function body you are creating side effects. Here, these side effects are unneeded and undesired. You should just return a string and then use console.log
when you call the function, for instance as you did in 2-more.
It is best to use a ternary statement to produce a value rather than to use it to cause side effects:
// your code
3 === 3 ? console.log("Yes") : console.log("No");
// preferred
console.log(3 === 3 ? "Yes" : "No");
Why don't you also make the distinction between new and used motorbikes?
As in 4-more, remove the console.log
statements from the function body.
The most efficient way to deal with the age
parameter id to handle it independently. That can simplify the conditions in your if
statements:
const condition = age <= 1 ? 'new' : 'used';
//...
return "it is a " + color + " " + condition + " car";
The first vehicle in the list should have the index of 1 (see assignment 4). You have a one-off error here.
See the age
comment above.
What if I call your function with -1 for code
?
It is best to place the vehicle array inside the function body. This makes your function pure: the most desirable form for a function.
Remove the console.log
statements from the function body.
Blank line 14 is meaningless.
The assignment asked for the array of vehicle names to be in singular form.
Your function should return a string. No console.log
in the body (i.e. no side effects). From the assignment:
... returns a corresponding advertisement text string ...
It is best to place the adMessage
variable inside the function body to make the function pure. Also, you can use const
in place of let
for addMessage
.
See 8-more.
Correct!
To use a metaphor: x
and y
are like twin brothers, they look the same but are separate entities. However, z
is just another name for x
.
Correct!
Correct!
Hi Mahmoud, here is my feedback on your homework for week 2.
Overall you have done a pretty good job. There are some minor points for improvement.
1. Be consistent in your use of quotes as string delimiter. Either choose single quotes or double quotes and then stick to that for all of your code (I prefer single quotes myself).
2. When you look for the position of an element in array you must take into account the possibility that you won't find it. Code like this will deal with that:
const index = favoriteAnimals.indexOf('meerkat');
console.log('the item you are looking for is at index :' + index);
if (index !== -1) {
favoriteAnimals.splice(1, 1);
}
3. For better readability it would be nice to separate blocks of related code which a blank line, just as you would separate paragraphs in a piece of text with a blank line:
const months = [
// ...
];
let daysTotal = 0;
for (let i = 0; i < months.length; i++) {
//...
}
console.log('The total of days in this year is : ' + daysTotal, 'days.');
if (daysTotal <= 365) {
//...
}
else {
//...
}
Notice also that I have moved the definition of the variable daysTotal
just before where it is first needed. This is a best practice: keep related code together.
4. There is a typo in a string constant: untill
-> until
. The spelling checker flags those errors with a green wavy underline.
5. There are a number of variables that you can declare with const
rather than let
. They are flagged by ESLint with green wavy underlines in VSCode. The const
keyword is preferred over let
if you do not intend to reassign a variable later.
6. If you want to report the paid hours (the assignment doesn't ask for it), you might want to do that in the HH:MM format. This output seems a bit awkward:
Only the paid hours = 18.666666666666668 hour
7. It is customary to place the โฌ-sign in front of the Euro money amount and print it with two decimals (accurate up to a Euro cent).
8. There is a typo in Maartje's name: Maatrje
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.