Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class ArtGallery {
- listOFArticles = [];
- guests = [];
- constructor(creator) {
- this.creator = creator;
- this.possibleArticles = {
- picture: 200,
- photo: 50,
- item: 250
- };
- }
- addArticle(articleModel, articleName, quantity) {
- if (!this.possibleArticles[articleModel.toLowerCase()]) {
- throw new Error(`This article model is not included in this gallery!`);
- }
- if (!this.listOFArticles.some(x => x.articleName == articleName)) {
- let articleModelToAdd = articleModel.toLowerCase();
- let article = {
- articleModelToAdd,
- articleName,
- quantity
- }
- this.listOFArticles.push(article);
- } else {
- this.listOFArticles.find(x => x.articleName == articleName).quantity += quantity // article не съществува, трябва да го вземеш от масива
- }
- return `Successfully added article ${articleName} with a new quantity- ${quantity}.`;
- }
- inviteGuest(guestName, personality) {
- if (this.guests.some(x => x.guestName == guestName)) {
- throw new Error(`${guestName} has already been invited.`);
- }
- let guest = {
- guestName,
- points : 0, //не можеш да зададеш points, защото го няма дефинирано
- purchaseArticle: 0
- }
- if (personality === 'Vip') {
- guest.points = 500;
- } else if (personality === 'Middle') {
- guest.points = 250;
- } else {
- guest.points = 50;
- }
- this.guests.push(guest); // не добавяш гостите в масива
- return `You have successfully invited ${guestName}!`;
- }
- buyArticle(articleModel, articleName, guestName) {
- if (!this.listOFArticles.some(x => x.articleName == articleName && x.articleModelToAdd == articleModel)) { // твоето проверява дали има елемент с това име и след това с този модел, а не елемент с двете заедно
- throw new Error(`This article is not found.`);
- }
- let articleToBuy = this.listOFArticles.find(x => x.articleModelToAdd == articleModel && x.articleName == articleName);
- if (articleToBuy.quantity <= 0) {
- throw new Error(`The {articleName} is not available.`);
- }
- if (!this.guests.some(x => x.guestName == guestName)) {
- throw new Error(`This guest is not invited.`);
- }
- let guest = this.guests.find(x => x.guestName == guestName); // тук твоето търси първия, който не е undefined, а трябва да намери елемента с това име
- if (guest.points < this.possibleArticles[articleModel.toLowerCase()]) { // тук не знам какво си се опитал да направиш
- return `You need to more points to purchase the article.`;
- } else {
- guest.points -= this.possibleArticles[articleModel.toLowerCase()]; // тук не знам какво си се опитал да направиш
- articleToBuy.quantity--;
- guest.purchaseArticle++;
- }
- return `${guestName} successfully purchased the article worth ${this.possibleArticles[articleModel.toLowerCase()]} points.`; // тук не знам какво си се опитал да направиш
- }
- showGalleryInfo(criteria) {
- if (criteria === 'article') {
- return `Articles information:\n${this.listOFArticles // тук имаш грешка в изписването с малка буква, вместо голяма
- .map(
- article =>
- `${article.articleModelToAdd} - ${article.articleName} - ${article.quantity}` // тук грешно взимат property, което го няма в този масив
- )
- .join('\n')}`;
- }
- if (criteria === 'guest') {
- return `Guests information:\n${this.guests
- .map(guest => `${guest.guestName} - ${guest.purchaseArticle}`)
- .join('\n')}`;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment