Build a Plant Nursery Catalog - Step 22

Tell us what’s happening:

The output of my function is working as intended. But I must be misunderstanding what the function is actually supposed to return. When I run the tests, I get “3. displayCatalog should return undefined, but found undefined.”

Your code so far

const ballerina = {
    commonName: "Spanish lavender",
    scientificName: "Lavandula stoechas",
    cultivar: "Ballerina"
}

const prettyPolly = {
    commonName: "Spanish lavender",
    scientificName: "Lavandula stoechas",
    cultivar: "Pretty Polly"
}

const willowVale = {
    commonName: "Spanish lavender",
    scientificName: "Lavandula stoechas",
    cultivar: "Willow Vale"
}

const hidcote = {
    commonName: "English lavender",
    scientificName: "Lavandula angustifolia",
    cultivar: "Hidcote"
}

const imperialGem = {
    commonName: "English lavender",
    scientificName: "Lavandula angustifolia",
    cultivar: "Imperial Gem"
}

const royalCrown = {
    commonName: "French lavender",
    scientificName: "Lavandula dentata",
    cultivar: "Royal Crown"
}

const catalog = new Map();
catalog.set(ballerina, { small: 20, medium: 15, large: 12 });
catalog.set(prettyPolly, { small: 31, medium: 14, large: 24 });
catalog.set(willowVale, { small: 3, medium: 5, large: 0 });
catalog.set(hidcote, { small: 33, medium: 13, large: 18 });
catalog.set(imperialGem, { small: 19, medium: 35, large: 28 });
catalog.set(royalCrown, { small: 40, medium: 22, large: 9 });

const removePlant = plant => catalog.delete(plant);

const sellPlants = (plant, size, potsNo) => {
    if (!catalog.has(plant)) return "Item not found.";
    const name = `${plant.scientificName} '${plant.cultivar}'`
    const pots = catalog.get(plant);
    if (pots[size] - potsNo < 0) {
        return `Not enough ${size} size pots for ${name}. Only ${pots[size]} left.`
    }
    pots[size] -= potsNo;
    return `Catalog successfully updated.`
}

// User Editable Region

const displayCatalog = () => {
    let megaString = "";  // Start with an empty string
    catalog.forEach((val, key) => {
        const newString = `${key.scientificName} '${key.commonName}': ${val.small} S, ${val.medium} M, ${val.large} L\n`;
        megaString += newString;  // Append newString to megaString
    });
    console.log(megaString)
    return megaString;
};

console.log(displayCatalog());

// User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36

Challenge Information:

Build a Plant Nursery Catalog - Step 22

Welcome to the forum @mirthtones

You cannot use escape characters with template literals.
Also, double check the plant names.

Happy coding

Thanks for the response, @Teller! I got the plant names fixed. The newline escape characters were working when I log out the result within the forEach, but I also get the same result if I do this instead:

const displayCatalog = () => {
    let megaString = "";
    catalog.forEach((val, key) => {
        const newString = `${key.scientificName} '${key.cultivar}': ${val.small} S, ${val.medium} M, ${val.large} L`;
        megaString += newString;
        megaString  += "\n"
    });
    console.log(megaString)
};

console.log(displayCatalog())

I really can’t tell if it’s a problem with my code, or if I’ve misunderstood the prompt. I wish I could see exactly what test 3 is checking for.

The out put of console.log(megaString) looks like this, which I believe is correct?:

Lavandula stoechas 'Ballerina': 20 S, 15 M, 12 L
Lavandula stoechas 'Pretty Polly': 31 S, 14 M, 24 L
Lavandula stoechas 'Willow Vale': 3 S, 5 M, 0 L
Lavandula angustifolia 'Hidcote': 33 S, 13 M, 18 L
Lavandula angustifolia 'Imperial Gem': 19 S, 35 M, 28 L
Lavandula dentata 'Royal Crown': 40 S, 22 M, 9 L

Ah, it did want both a console log and a return statement inside the function; the failure message that the test was returning (“should return undefined”) was just really misleading. Thanks again!

1 Like

I wonder if it gives undefined because the actual catalog would be really long… I’ll open a bug ticket for this

1 Like