hyf-javascript3's Introduction
hyf-javascript3's People
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.