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 * Recites the lyrics to '99 Bottles of Beer on the Wall'.
3 * Handles special cases for 1 bottle, 0 bottles, and the final restart verse.
4 *
5 * @param {number} initialBottlesCount - The starting number of bottles (0-99)
6 * @param {number} takeDownCount - How many verses to recite (default: 1)
7 * @return {string[]} - Array of verses
108 */
119export const recite = (initialBottlesCount, takeDownCount = 1) => {
12 throw new Error('Remove this line and implement the function');
10 // Edge Case: Invalid input types
11 if (typeof initialBottlesCount !== 'number' || typeof takeDownCount !== 'number') {
12 throw new Error('Both parameters must be numbers');
13 }
14
15 // Edge Case: Negative numbers
16 if (initialBottlesCount < 0 || takeDownCount < 0) {
17 throw new Error('Parameters must be non-negative');
18 }
19
20 // Edge Case: takeDownCount of 0
21 if (takeDownCount === 0) {
22 return [];
23 }
24
25 const verses = [];
26
27 for (let i = 0; i < takeDownCount; i++) {
28 const currentBottles = initialBottlesCount - i;
29
30 // Edge Case: Going below 0 bottles
31 if (currentBottles < 0) {
32 break;
33 }
34
35 let line1, line2;
36
37 if (currentBottles === 0) {
38 line1 = 'No more bottles of beer on the wall, no more bottles of beer.';
39 line2 = 'Go to the store and buy some more, 99 bottles of beer on the wall.';
40 } else if (currentBottles === 1) {
41 line1 = '1 bottle of beer on the wall, 1 bottle of beer.';
42 line2 = 'Take it down and pass it around, no more bottles of beer on the wall.';
43 } else {
44 line1 = `${currentBottles} bottles of beer on the wall, ${currentBottles} bottles of beer.`;
45
46 if (currentBottles - 1 === 1) {
47 line2 = 'Take one down and pass it around, 1 bottle of beer on the wall.';
48 } else {
49 line2 = `Take one down and pass it around, ${currentBottles - 1} bottles of beer on the wall.`;
50 }
51 }
52
53 verses.push(line1);
54 verses.push(line2);
55
56 // Add empty line between verses except for the last one
57 if (i < takeDownCount - 1) {
58 verses.push('');
59 }
60 }
61
62 return verses;
1363};
64
65// Handled Edge Cases: Invalid input types, negative numbers, takeDownCount of 0, going below 0 bottles
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.