Build a Plant Nursery Catalog - Step 15

Tell us what’s happening:

I’m confused what this is asking. It states “takes a plant object as an argument”, but then has me log a test of the function using a string as an argument. Is this to test if the function is behaving correctly by passing it an incorrect argument? Or does it want me to check if the string name passed has an associated object for that string name?

Either way, it doesn’t look like the function I wrote for it is what it’s looking for. Could you point me in the right direction? Thank you!

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 });


// User Editable Region

function removePlant(plantObj) {
    if (catalog.has(plantObj)) {
        catalog.delete(plantObj);
        return true;
    } else {
        return false;
    };
};

console.log(removePlant("ballerina"));

// User Editable Region


const sellPlants = (plant, size, potsNo) => {
    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.`
}

console.log(sellPlants(ballerina, "small", 10));

console.log(catalog)

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36

Challenge Information:

Build a Plant Nursery Catalog - Step 15

and that one will not remove anything, it’s not a key

follow the instructions and continue forward

yes, I’m aware that it won’t remove anything because it’s not a key, and the argument wants a key. The function seems to work fine passing in a key.

My issue is that, following the instructions of inputting console.log(removePlant(“ballerina”)), I am still failing the tests.

3. Your removePlant function should call the delete method on catalog.
4. removePlant(item) should delete item from your catalog.

Seeing as the function seems to do what it’s supposed to with a proper key/plant object argument input, it is unclear why I am failing the tests.

try without the if/else
the method already deals with that

Well it’s solved.

Should probably note that nowhere in the lesson does it state that the .delete() method returns true or false, so this step in the workshop is working entirely off the assumption that the student somehow knows that. Kind of frustrating.

you can use the delete method, which takes a key as argument and removes the entry associated with that key. It returns a boolean indicating if the removal has been successful.

You can always do a search about a method to get more details about how it works as well.

1 Like

Welp I guess that’s on me. I can’t really say why the phrasing didn’t click while I was on this step. Part of me is hoping that information wasn’t there before and I’m just being gaslit, but that’s probably just me hoping I’m not starting to go a little crazy from all these hours working my way through JavaScript lol.

I was pretty exhausted while working on this workshop, so I apologize for letting that frustration work its way into my replies. I was going over the issue I was having with this step with a friend and he seemed to have as hard of a time figuring it out as I was. Either way though, I very much appreciate the help!

1 Like

Do not worry about it at all. It’s very easy to miss a detail like that which doesn’t seem important at first.

The instructions are precise and carefully worded so it always helps to have a careful read through if you have a problem later. They do not always contain everything you might need to know though, so search external resources might also be needed.