Skip to content

Week 4 assignment Joann Cahill #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 14 commits into
base: master
Choose a base branch
from

Conversation

jcahill53
Copy link

No description provided.

cardsWorthTen.js Outdated

for (let i = 0; i < filteredCards.length; i++) {

filteredVal = console.log(`${filteredCards[i].displayVal}`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah . . . . The key here is what we want the function to return. Remember that console.log() is just a side effect . . . it simply executes the writing of values to the console. It does not return values themselves. So what happens here is that the program executes the log on each loop, but filteredVal is always undefined.

So going back to the hint on line 69: returns a string of the card display values where the value is equal to 10

so this `filteredVal that you retrun on line 86 ought to be a string that you build up from the filtered card results.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get that I have to turn this into a string but I can't come up with a successful approach. I tried creating another array called stringVal and then used both join ( stringVal = filteredVal.join(', ');) and stringify (JSON.stringify(filteredVal)) to try to get them to link together into that array. I keep getting an error. Everything I read about join and stringify talks about stringing/joining properties in a single object. I don't see anything about joining values in a property across multiple objects.

cardsWorthTen.js Outdated

};

return (filteredVal)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for the parenthesis here, you can just do return filteredVal

cardsWorthTen.js Outdated



cardsWorthTen(cards);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see you removed the console log that was provided by the boiler plate, and that is adding to the confusion over console.log() You want to keep that as is, because the mental model is more accurately like "the function returns a value, but the console log here simply writes the value that comes from calling the function to output so that we can see it"

In general, console.log() is a handy tool for developers, but really does not play a role in actual programming, other than giving you a way to peek at values when you need to. For most production code you will delete all of the console.log() statements before shipping. It's just a helper.


let filteredCards = cards.filter((card) => card.val === 10);
let filteredVal = [];

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also a hint on how you might filter values and make a string . . . You have the array of card objects already. In your loop below you are reaching the value correctly. Now instead of console logging them, tack them on to the end of a new collection. No single way to do this, you could start with an empty string and concatenate on to the end . . or perhaps make an empty array that you push the new values into, and then later use Array.join(', ') to convert the array into a string of those values separated by a comma and a space.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants