-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathShopScript
31 lines (23 loc) · 914 Bytes
/
ShopScript
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
Duplicate this as many times as you want, also depending on how many shop items there may be.
{ name: "ID", price: ?, description: ?." },
{ name: "ID", price: ?, description: ?." },
function displayShop() {
console.log("Welcome to the item shop!\n");
console.log("Available Items:");
shopItems.forEach((item, index) => {
console.log(`${index + 1}. ${item.name} - ${item.price} gold coins`);
console.log(` ${item.description}`);
});
}
function purchaseItem(itemIndex, playerGold) {
const selectedItem = shopItems[itemIndex - 1];
if (!selectedItem) {
console.log("Invalid item selection.");
return;
}
if (playerGold < selectedItem.price) {
console.log("Insufficient gold coins to purchase this item.");
return;
}
console.log(`You have purchased ${selectedItem.name} for ${selectedItem.price} gold coins.`);
}