agent

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 - How many verses to generate (default: 1)
5 * @return {string[]} - Array of verses
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 numbers
14 if (initialBottlesCount < 0 || takeDownCount < 0) {
15 throw new Error('Parameters must be non-negative');
16 }
17
18 // Edge Case: takeDownCount is 0
19 if (takeDownCount === 0) {
20 return [];
21 }
22
23 const verses = [];
24
25 for (let i = 0; i < takeDownCount; i++) {
26 const currentBottles = initialBottlesCount - i;
27
28 // Edge Case: Current bottles count goes below 0
29 if (currentBottles < 0) {
30 break;
31 }
32
33 let line1, line2;
34
35 if (currentBottles === 0) {
36 line1 = 'No more bottles of beer on the wall, no more bottles of beer.';
37 line2 = 'Go to the store and buy some more, 99 bottles of beer on the wall.';
38 } else {
39 // Handle first line
40 const bottleWord1 = currentBottles === 1 ? 'bottle' : 'bottles';
41 line1 = `${currentBottles} ${bottleWord1} of beer on the wall, ${currentBottles} ${bottleWord1} of beer.`;
42
43 // Handle second line
44 const nextBottles = currentBottles - 1;
45 if (nextBottles === 0) {
46 line2 = 'Take it down and pass it around, no more bottles of beer on the wall.';
47 } else if (nextBottles === 1) {
48 line2 = 'Take one down and pass it around, 1 bottle of beer on the wall.';
49 } else {
50 line2 = `Take one down and pass it around, ${nextBottles} bottles of beer on the wall.`;
51 }
52 }
53
54 verses.push(line1);
55 verses.push(line2);
56
57 // Add empty line between verses except for the last one
58 if (i < takeDownCount - 1) {
59 verses.push('');
60 }
61 }
62
63 return verses;
1364};
65
66// Handled Edge Cases: Invalid input types, negative numbers, 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.