GithubHelp home page GithubHelp logo

hyf-javascript1's People

Contributors

neveenatik avatar

Watchers

 avatar

Forkers

aalhommada

hyf-javascript1's Issues

Feedback homework week 3

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

I think you have done pretty well. I particularly like how you have attempted to make your functions pure and without side effects (but see assignment 7).

Please review on how to use the ternary operator.

1-more.js

  • Your program doesn't tell the truth:

    Sum of 1, 2, 5 is: 6
    

2-more.js

  • There is a semicolon missing in line 5 as flagged 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.

3-more.js

Excellent! But I would remove blank lines 4 & 8. And add a blank line before and after a function definition.

4-more.js

Excellent!

5-more.js

  • It is considered a bad practice to use more than one statement on a single line.

  • While you can use a ternary operator like you do here, I would prefer to use it in such a way that you use the resulting value. And of course, console.log doesn't return a value. You could do this instead:

    'use strict';
    const test = 3;
    console.log(test === 3 ? 'yes' : 'no');
  • I like the way you avoided an ESLint complaint by introducing the test variable.

6-more.js

Excellent! But be consistent in how you use quotes. Either all single quotes (my preference) or all double quotes.

7-more.js

  • Use camelCase: Vehicles -> vehicles.

  • I would move the vehicles variable inside the function body, to make the function pure.

  • You should review the documentation for the ternary operator. It returns a conditional value. This is much cleaner than what you did:

    const condition = age > 1 ? 'used' : 'new';

    Also, try and avoid to reassign a parameters. It is considered a bad practice. The age parameter denotes a numeric age. The string constants 'used' and 'new' do not represent an age, but rather the condition of the car.

  • You don't need a for loop. You can just test the value of type to check whether it is in the range of your array and, if true, use it directly as an index. The whole code with proper formatting and use of blank lines could look like this:

    'use strict';
    
    function vehicleType(color, type, age) {
      const vehicles = ['car', 'motorbike', 'caravan', 'bike'];
      const condition = age > 1 ? 'used' : 'new';
      if (type > 0 && type <= vehicles.length) {
        return 'a ' + color + ' ' + condition + ' ' + vehicles[type - 1];
      }
      return 'unknown vehicle';
    }
    
    console.log(vehicleType('green', 3, 1));
    console.log(vehicleType('red', 5, 1));

8-more.js, 9-more.js

  • You are almost there: there should be no comma before the word 'and':

    Amazing Joe's Garage, we service cars, motorbikes, caravans, and bikes.
    //                                                         ^no comma here
    

10-more.js

  • I like the way you have avoided hard-coded array indices. In JS2 week 2 you will learn other ways of doing this that do not involve using a for loop.

11-more.js

  • A blank line here and there would help to make the code more readable.

  • You produce a lot of output. I would prefer just a single line which tells whether the arrays are equal or not. In your case I have to wade through the output to draw my conclusion.

  • You can terminate your for loop with a break statement as soon as you have detected that they arrays are not equal. In that case, any further work in the loop is a waste of time and energy.

  • If I change your arrays to:

    const x = [1, 2, 3];
    const y = [1, 2, 5];

    I get this output (only last the two lines shown), which doesn't make sense:

    1,2,3 is not equal to 1,2,5
    1,2,3 equals 1,2,5 
    
  • Using parseInt() on an array is not meaningful. If you look up the documentation for parseInt() you will find that it expects a string argument. So what will actually happen in your case is that, for instance, the array [1, 2, 3] is first converted to the string '1,2,3' and then parsed to the value of 1, because parseInt() stops as soon as it finds something other than a digit (in this case a comma).

12-more.js

Correct!

13-more.js

Correct! But the variable result is unneeded and can be removed.

Feedback homework week 2

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

Overall, pretty good work. Nice that you have used some pure functions to do some of the work.

1. The files 1-strings.js and 4-maartjeswork.js are missing a 'use strict'; line.

2. 2-arrays.js: 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).

3. The meerkat is placed at the wrong position, the assignment asked this:

2.3 Now add Jim's favorite animal to the array, it's 'meerkat', but make sure it will be placed after 'blowfish' and before 'capricorn'.

4. You have used the .findIndex() array method to find the index of the meerkat. While that is perfectly fine, when looking for a simple value in an array most programmers prefer to use .indexOf() because that does not require an extra function:

const found = favoriteAnimals.indexOf("meerkat");

We use .findIndex() when the array elements are not simple values, but for instance JavaScript objects for which you want to find an object that has a certain property value. In that case .indexOf() is of no use.

4. 3-loops.js: Nice use of a function, and a good name for it too. The function is pure, which I like. I have a personal preference to use a function statement rather than a function expression in cases like this:

function sumDays(months) {
  //...
  return days;
}

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:

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

function sumDays(months) {
  //...
}

if (sumDays(months) === 365) {
  //...
} else {
  //...
}

5. 4-maartjeswork.js: The comments from 4 (function statement, blank lines) also apply here.

In line 45 you have declared multiple variables in a single let statement. While that was often done in the past when we only had the var keyword, this is nowadays considered a bad practice. You are now recommended to declare variables at the point where your first need them.

In fact, you don't need the hour variable at all and you are unnecessarily repeating a calculation in the loop body, which can easily be done once, after the loop. The resulting code would be:

function declarableTime(tasks) {
  let time = 0;
  for (let i = 0; i < tasks.length; i++) {
    if (tasks[i].duration >= 120) {
      time += tasks[i].duration;
    }
  }
  return time / 60;
}

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.