Art Gallery - JS Advanced Final Retake Exam - 12 August 2021
Здравейте,
Моля за помощ за следната задача:
https://judge.softuni.org/Contests/Practice/Index/3089#1
Решение - 80/100:
https://pastebin.com/m2E0v3mC
Благодаря!
Здравейте,
Моля за помощ за следната задача:
https://judge.softuni.org/Contests/Practice/Index/3089#1
Решение - 80/100:
https://pastebin.com/m2E0v3mC
Благодаря!
If the quantity of the current article is equal to 0, return message:
"The {articleName} is not available."
If the guestName is not present in the guests array, return message:
"This guest is not invited."
;-)
buyArticle(articleModel, articleName, guestName) {
let findModel = this.listOfArticles.find((x) => { return x.articleModel === articleModel.toLowerCase() && x.articleName === articleName });
let guest = this.guests.find((x) => { return x.guestName === guestName });
if (!findModel) {
throw new Error("This article is not found.")
}
if (findModel.quantity === 0) {
// throw new Error(`The ${articleName} is not available.`) // no Error throwing!!!
return `The ${articleName} is not available.`;
}
if (!guest) {
// throw new Error("This guest is not invited."); // no Error throwing!!!
return "This guest is not invited.";
}
let neededPoints = Number(this.possibleArticles[articleModel.toLowerCase()]);
let userPoints = Number(guest.points);
if (neededPoints <= userPoints) {
guest.points -= neededPoints;
findModel.quantity -= 1;
guest.purchaseArticle += 1;
} else {
return "You need to more points to purchase the article.";
}
return `${guestName} successfully purchased the article worth ${neededPoints} points.`
}
Thank you!!! :)