Git Product home page Git Product logo

hyf-javascript3's People

Contributors

abdullahweb avatar

hyf-javascript3's Issues

Week 7 - OOP

Hi @abdullahWeb ,

I like that you have only one parameter for the constructor of the Movies class and that for the other properties you're pushing values to an array rather than having to use an array as an argument for the constructor.

There are a few issues though:

1. In both the Movies and Staff classes, you have a getProperty() method for each object property - for example get getName() for the name property in the Staff class. I think, however, that all these methods are unnecessary because you're not doing anything with the object properties. You're just returning them. So, if, for example you call getName() on the instance Leonardo, that achieves the same thing as saying Leonardo.name. That is,

this

                      ` console.log( Leonardo.getName() );`

produces the exact same result - "Leonardo" - as

                      `console.log( Leonardo.name );`

Why have a method that just returns a property if you can already access that property by just using the usual object.key method? In my opinion, the only way having getName( ) would be useful is if you were returning the name property with something else. For example:

                       ```
                       getName() {
                            return `Name: this.name`;
                        }
                        ```

This way if you want to access the name property as it is outside the Leonardo object, you'd be able to do so with just Leonardo.name, but if you wanted to log it to the console and have it show some additional text that indicates what it is (a name), you'd use console.log( Leonardo.getName() ) . This would log Name: Leonardo rather than just Leonardo.

2. With the Movies class, you're adding new values to the ratings property array whenever addRating() is called on an instance of Movies. So, I think what you should be doing with the getRating() method is using these ratings that you've pushed to the array to calculate an average rating rather than just returning the ratings. You could do something like this:

           ```
           getRating() {

                  let ratingsTotal = 0;
  
                  this.ratings.forEach(rating => {
                        ratingsTotal += rating;
                   });
  
                  console.log( `Average Rating: ${ratingsTotal / this.ratings.length}` );
            }
           ```

This way, if you say, for example, Inception.getRating(); after you've added ratings for Inception, it would log Average Rating: 8.34 to the console instead of just returning an array of ratings.

3. I don't think the last few lines of code are doing what you were expecting them to. This

             ```
              console.log(Inception.getActors().map(function (actor) {

                     return `The Greatest actors ever are:  ${actor}`;

              }));
            ```

logs this array to the console because you're using map:

["The Greatest actors ever are: Leonardo Dicaprio", "The Greatest actors ever are: Emily Mortimer", "The Greatest actors ever are: Mark Ruffalo"]

whereas I think you were planning to do this:

      `console.log( `The greatest actors ever are:  ${Inception.getActors()}` );`

which produces:

           `The greatest actors ever are:  Leonardo Dicaprio,Emily Mortimer,Mark Ruffalo`

Or, if you were trying to log a statement for each actor:

               ```
              Inception.getActors().forEach(function (actor) {

                  console.log(`One of the greatest actors ever is:  ${actor}`);

               });
              ```

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.