@Chanda-Abdul
Posted
👋 Hey there! Congratulations on completing your project. Overall, everything looks amazing and functions well. I appreciate that you were able to incorporate tests.
Here are some suggestions to help improve your code and align with Angular best practices:
- Consider using TypeScript to provide abstractions in your code. Instead of hard coding paper, rock, and scissors directly into the template, you could create an
opponent.model.ts
file to abstract this data. By abstracting the data, it would greatly enhance scalability and readability. Similar to this
const opponent: [string, boolean] = [
{ name: 'rock', bonus: false },
{ name: 'paper', bonus: false },
{ name: 'scissors', bonus: false },
{ name: 'lizard', bonus: true },
{ name: 'spock', bonus: true },
];
- When accessing the data in your template, consider using Angular pipes to format and transform the values. Pipes are a powerful feature in Angular that can help with data manipulation and presentation. Utilizing pipes will make your code more modular and easier to maintain.
<ul class="opp">
<li *ngFor"let opp in opponents"> {{opp.name | capitalize}}
<span *ngIf="opp.bonus === true">bonus</span>
</li>
</ul>
- To encapsulate all the game play functionality, consider creating a service. This service can hold the logic for game rules, scoring, and other related functionality. Additionally, you can leverage RxJS observables to keep track of the game results and opponents. Observables provide a reactive way of handling asynchronous events, which can be beneficial for real-time updates and data synchronization.
By incorporating these suggestions, you'll be following Angular conventions and best practices, making your code more maintainable and scalable.
Keep up the great work, and if you have any questions or need further clarification, feel free to reach out. Happy coding!
Marked as helpful
@oroszlanolo
Posted
Thanks @Chanda-Abdul, Your feedback was helpful. I will keep these in mind in the future.