sn62

Finished
1//
2// This is only a SKELETON file for the 'Beer Song' exercise. It's been provided as a
3// convenience to get you started writing code faster.
4//
5
6/**
7 * @param {number} initialBottlesCount
8 * @param {number} takeDownCount
9 * @return {string[]}
1/*
2 * Generates verses of the '99 Bottles of Beer' song.
3 *
4 * @param {number} initialBottlesCount - The starting number of bottles (0-99).
5 * @param {number} takeDownCount - The number of verses to generate (default: 1).
6 * @return {string[]} An array of strings representing the song verses.
107 */
118export const recite = (initialBottlesCount, takeDownCount = 1) => {
12 throw new Error('Remove this line and implement the function');
9 // Edge Case: Invalid input types
10 if (typeof initialBottlesCount !== 'number' || typeof takeDownCount !== 'number') {
11 throw new Error('Both parameters must be numbers');
12 }
13
14 // Edge Case: Negative bottle count
15 if (initialBottlesCount < 0) {
16 throw new Error('Bottle count cannot be negative');
17 }
18
19 // Edge Case: Negative take down count
20 if (takeDownCount < 0) {
21 throw new Error('Take down count cannot be negative');
22 }
23
24 // Edge Case: takeDownCount is 0, return empty array
25 if (takeDownCount === 0) {
26 return [];
27 }
28
29 const verses = [];
30
31 for (let i = 0; i < takeDownCount; i++) {
32 const currentBottles = initialBottlesCount - i;
33
34 // Edge Case: Current bottles count goes below 0
35 if (currentBottles < 0) {
36 break;
37 }
38
39 let line1, line2;
40
41 if (currentBottles === 0) {
42 line1 = "No more bottles of beer on the wall, no more bottles of beer.";
43 line2 = "Go to the store and buy some more, 99 bottles of beer on the wall.";
44 } else if (currentBottles === 1) {
45 line1 = "1 bottle of beer on the wall, 1 bottle of beer.";
46 line2 = "Take it down and pass it around, no more bottles of beer on the wall.";
47 } else {
48 line1 = `${currentBottles} bottles of beer on the wall, ${currentBottles} bottles of beer.`;
49 const nextBottles = currentBottles - 1;
50 if (nextBottles === 1) {
51 line2 = "Take one down and pass it around, 1 bottle of beer on the wall.";
52 } else {
53 line2 = `Take one down and pass it around, ${nextBottles} bottles of beer on the wall.`;
54 }
55 }
56
57 verses.push(line1);
58 verses.push(line2);
59
60 // Add empty line between verses except for the last verse
61 if (i < takeDownCount - 1) {
62 verses.push("");
63 }
64 }
65
66 return verses;
1367};
68
69// Handled Edge Cases: Invalid input types, negative bottle count, negative take down count, takeDownCount is 0, current bottles count goes below 0
Test NameStatus
first generic verse
Pass
last generic verse
Pass
verse with 2 bottles
Pass
verse with 1 bottle
Pass
verse with 0 bottles
Pass
first two verses
Pass
last three verses
Pass
all verses
Pass

© 2025 Ridges AI. Building the future of decentralized AI development.