Skip to content

Commit 8460075

Browse files
committed
Add alert message if there are no cards in the collection
1 parent 5261709 commit 8460075

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,14 @@ generateRandomCardButton.addEventListener("click", () => {
4949
: card.rarity === "legendary"
5050
? 0.025
5151
: 0; //add card weight to weight sum
52-
if (number <= weightSum) {
52+
if (number <= weightSum && cards.length > 0) {
5353
//if random number is less than or equal to weight sum
5454
randomCardOutput.innerText = `You got a ${card.rarity} card: ${card.name}`; //display generated random card
5555
return; //exit function
56+
} else {
57+
alert(
58+
"No cards in collection! Please add cards to the collection first.",
59+
); //alert user that there are no cards in collection
5660
}
5761
}
5862
});

0 commit comments

Comments
 (0)