great

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 the lyrics for the beer song starting from a given number of bottles.
3 * @param {number} initialBottlesCount - The starting number of bottles (0-99).
4 * @param {number} takeDownCount - The number of verses to generate (default is 1).
5 * @return {string[]} - An array of strings representing the lyrics.
106 */
117export const recite = (initialBottlesCount, takeDownCount = 1) => {
12 throw new Error('Remove this line and implement the function');
8 // Edge Case: Invalid input types
9 if (typeof initialBottlesCount !== 'number' || typeof takeDownCount !== 'number') {
10 throw new Error('Both parameters must be numbers');
11 }
12
13 // Edge Case: Negative initial bottles count
14 if (initialBottlesCount < 0) {
15 throw new Error('Initial bottles count cannot be negative');
16 }
17
18 // Edge Case: Negative take down count
19 if (takeDownCount < 0) {
20 throw new Error('Take down count cannot be negative');
21 }
22
23 // Edge Case: takeDownCount is 0, return empty array
24 if (takeDownCount === 0) {
25 return [];
26 }
27
28 const verses = [];
29
30 for (let i = 0; i < takeDownCount; i++) {
31 const currentBottles = initialBottlesCount - i;
32
33 // Edge Case: Current bottles count goes below 0
34 if (currentBottles < 0) {
35 break;
36 }
37
38 // Handle special cases for different bottle counts
39 if (currentBottles === 0) {
40 verses.push('No more bottles of beer on the wall, no more bottles of beer.');
41 verses.push('Go to the store and buy some more, 99 bottles of beer on the wall.');
42 } else if (currentBottles === 1) {
43 verses.push('1 bottle of beer on the wall, 1 bottle of beer.');
44 verses.push('Take it down and pass it around, no more bottles of beer on the wall.');
45 } else if (currentBottles === 2) {
46 verses.push('2 bottles of beer on the wall, 2 bottles of beer.');
47 verses.push('Take one down and pass it around, 1 bottle of beer on the wall.');
48 } else {
49 verses.push(`${currentBottles} bottles of beer on the wall, ${currentBottles} bottles of beer.`);
50 verses.push(`Take one down and pass it around, ${currentBottles - 1} bottles of beer on the wall.`);
51 }
52
53 // Add empty string for spacing between verses, except after the last verse
54 if (i < takeDownCount - 1) {
55 verses.push('');
56 }
57 }
58
59 return verses;
1360};
61
62// Handled Edge Cases: Invalid input types, negative initial bottles 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.