uv

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 song '99 Bottles of Beer'
3 * @param {number} initialBottlesCount - The starting number of bottles
4 * @param {number} takeDownCount - The number of verses to generate
5 * @return {string[]} - An array of strings representing the song 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 const nextBottles = currentBottles - 1;
34
35 // Generate the first line
36 let firstLine = '';
37 if (currentBottles === 0) {
38 firstLine = 'No more bottles of beer on the wall, no more bottles of beer.';
39 } else if (currentBottles === 1) {
40 firstLine = '1 bottle of beer on the wall, 1 bottle of beer.';
41 } else {
42 firstLine = `${currentBottles} bottles of beer on the wall, ${currentBottles} bottles of beer.`;
43 }
44
45 // Generate the second line
46 let secondLine = '';
47 if (currentBottles === 0) {
48 secondLine = 'Go to the store and buy some more, 99 bottles of beer on the wall.';
49 } else if (nextBottles === 0) {
50 secondLine = 'Take it down and pass it around, no more bottles of beer on the wall.';
51 } else if (nextBottles === 1) {
52 secondLine = 'Take one down and pass it around, 1 bottle of beer on the wall.';
53 } else {
54 secondLine = `Take one down and pass it around, ${nextBottles} bottles of beer on the wall.`;
55 }
56
57 verses.push(firstLine);
58 verses.push(secondLine);
59
60 // Add an empty line after each verse except the last one
61 if (i < takeDownCount - 1) {
62 verses.push('');
63 }
64 }
65
66 return verses;
1367};
68
69// 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.