Giter VIP home page Giter VIP logo

hyf-javascript1's People

Contributors

wael-alhomsi avatar

Watchers

 avatar

hyf-javascript1's Issues

Feedback homework week 2

Hi Wael, here is my feedback on your homework for week 2.

Overall you have done a good job. The code works as expected. Your choice of variable names is excellent.

1-strings.js

1. It is best to define your variables just before you need them. This keeps related code together. In this tiny program it is not urgent, but the principle remains:

const re = /,/gi;
console.log(myString.replace(re, ' '));

Both variables can be declared as const. You should use const instead of let if you do not intend to reassign the variable somewhere else in your code.

2-arrays.js

2. This file has formatting issues. Please check the VSCode Tips on how to set up VSCode to automatically format your code.

3. 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).

4. Rather than using the expression favoriteAnimals.indexOf('meerkat') twice, you could define a variable and then use that:

const index = favoriteAnimals.indexOf('meerkat');

3-months.js

5. This file has formatting issues.

6. For better readability it would be nice to separate blocks of related code with a blank line, just as you would separate paragraphs in a piece of text with a blank line:

const months = [
  //...
];

let totalDays = 0;

for (let i = 0; i < months.length; i++) {
  //...
}

if (totalDays === 365) {
  //...
} else {
  //...
}

4-maartje.js

7. This file has formatting issues.

8. You can use const instead of let for those variables that do not (need to) change. This will also remove the green wavy underlines (=warning) from ESLint.

Feedback homework week 3

Hi Wael, here is my feedback on your homework for week 3.

1-more

Correct!

But by calling your function invoiceAmount() you are suggesting that this function can only be used for that purpose, while in fact it can add up any three numbers. The more generic name sum() would invite wider usage.

Also, make sure that your function name suggests an action, which is usually done by embedding a verb in the name. If your function is specifically about computing invoice amounts you could call it for instance computeInvoiceAmount().

Note that the let invoice could have been const invoice, as indicated by ESLint. 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.

2-more

Correct!

3-more

Correct!

(There is a missing semicolon in line 4, as flagged by ESLint).

4-more

Correct!

5-more

Correct!

6-more

Correct, but you can simplify your code by dealing with the age separately:

function vehicleType(color, code, age) {
  const condition = age <= 1 ? 'new' : 'used';
  if (code === 1) {
    return 'a ' + color + ' ' + condition + ' car';
  } else if (code === 2) {
    return 'a ' + color + ' ' + condition + ' motorbike';
  } else if (code > 2) {
    return 'a ' + color + ' ' + condition + ' unknown vehicle';
  }
}

7-more

Your code produces the correct results but is overly complicated. It is best to deal with color, code and age individually and then compose a result through a concatenation of the individual results, like this:

function vehicleType(color, code, age) {
  const arrVehicleTypes = ['car', 'motorbike', 'caravan', 'bike'];
  const condition = age <= 1 ? 'new' : 'used';
  const vehicle = (code >= 1 && code <= arrVehicleTypes.length)
    ? arrVehicleTypes[code - 1]
    : 'unknown vehicle';
  return 'a ' + color + ' ' + condition + ' ' + vehicle;
}

Also, notice that I placed the vehicles array inside the function body so that the function no longer depends on an external variable and is now self-contained: it has become pure: the most desirable form for a function.

8-more

Correct. But mind the code formatting. You should never add code on the same line after a closing curly brace:

// bad
... } return 'Amazing Wael\'s Garage, we service ' + str + ' and ' + arr[arr.length - 1] + 's.';

// good
... }

return 'Amazing Wael\'s Garage, we service ' + str + ' and ' + arr[arr.length - 1] + 's.';

See Code Formatting.

9-more

Correct! (Mind code formatting)

10-more

Correct!

11-more

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.

12-more

Correct!

13-more

Correct!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.