Basic JavaScript Day 3: Homework

Hey @carlost2672543 thanks for replying I appreciate that! I’ll take what you said on board. I’ll try and give it another go over the weekend with a fresh mind and see what happens and take it from there. As you say I can come back to it so I’ll mark the lessons I find tricky and see if they improve as I progress :+1:

2 Likes

Not completely understanding the relationship between the SWITCH and CASE functions. I grasp the basic concept, but not the implementation of its mechanics in practice. Hope to get some more exercises to practice it

1 Like

Hi Scott! It is a tough one isn’t it! If you look back in this thread you’ll see that a few others got tripped up by it too. I have written 2 posts with some additional hints and pointers for this exercise and they are linked here:

This one explains a bit more about how the ‘switch’ works:

And this one explains a strategy on how to tackle this particular problem

For the last one you may need to have a look at the screenshot by Lina too, but it is not too far above that.

With Carlos’ tips and these posts you may be able to tackle the problem. If you need more help - just shout out.

3 Likes

Hi Enzo,

Maybe also have a look at this link I just posted as I try to explain how it works:

If you need more help let us know.

2 Likes

Thank you Syl, I find the default statement a bit more comprehensible as well now (found it in the next exercise) and did too much code (apparently) to get to the same answer. Will try it out!

1 Like

Thanks for the info @syllie ill have another go at it over the weekend! Many thanks :pray:

2 Likes

Hi there,

Don’t really understand why a property needs to be in single or double quotes when updating it with bracket notation, since we’ve learned that only properties with spaces in their name need quotes?

const myDog = {
  "name": "Happy Coder",
  "legs": 4,
  "tails": 1,
  "friends": ["freeCodeCamp Campers"]
};

myDog["bark"] = "woof" instead of myDog[bark] = "woof"

Pls i don’t know where to click to code,it seems the page is unresponsive. Can someone give me a guide?
Thanks

You don’t have a variable or function called bark in your code. The property name needs to be a string when dealing with quote marks.

However, dot notation is different. With dot notation, you must use a property name without quote marks. This is because handling a property with dot notation is not done so as a string.

In short myDog.bark is equivalent to myDog["bark"}.

I don’t think there’s a “why” so much as the syntax not allowing it.

1 Like

Please go to freeCodeCamp.org to sign up and get an account and get started!

If you go back to the first lesson, you’ll find that info

Hi Remco,

That is once again a good question and it shows that you are working to wrap your head around complex things. So I am gonna quote a paragraph from MDN:

An object property name can be any valid JavaScript string, or anything that can be converted to a string, including an empty string. However, any property name that is not a valid JavaScript identifier cannot use dot notation. For example, a property name that has a space or a hyphen, that starts with a number, or that is held inside a variable can only be accessed using the square bracket notation. This notation is also very useful when property names are to be dynamically determined, i.e. not determinable until runtime.

Understand that we talk about the ‘property name’ here, thus: name, legs, tails, friends, bark in your example. So you ‘may use quotes’ and if not, it will internally convert it to string anyways. But you cannot omit the quotes when you have weird characters, or spaces in there.

I just saw that Ramon also tuned in - and explains the next thing. IF your property has spaces in the name, you MUST use quotes, and you can no longer access them with dot notation, you must use bracket notation.

And in bracket notation, you ALWAYS use quotes (either single or double)

myObject.firstName
myObject['firstName']
myObject["firstName"]

# if your property has spaces or other invalid characters, you must use bracket notation
const person = {
"first Name" : "Happy Coder"
}
person['first Name']

are all valid accessors. Please have a look at the linked MDN doc.

3 Likes

Good day from this end. Can anyone send a list of all assignments that has been given from the beginning of this bootcamp? I haven’t been online lately. Thanks in anticipation.

3 Likes

Hi @omotoshoayomi2954237

Assignments are just follow freeCodeCamp curriculum, no pressure. :wink:

2 Likes

Hi Omotosho!

At the current time, we have done the following sections completetly:

  • Basic JavaScript
  • ES6
  • Regular Expressions

We have also done 2 projects:

  • Palindrome Checker
  • Roman Numeral Converter

When in doubt, you can refer to the bootcamp dashboard to see the timeline.

Hope this helps.

1 Like

Hi Syl,
Thanks again :slight_smile:

2 Likes

Thanks, Ramón! I think I used to be a “why” child :slight_smile:

2 Likes

In that case I envy you, Remco! Asking why challenges the norms of software development and moves things forward, so thank you.

1 Like

Hi Ramon, you’re welcome :slight_smile:

1 Like

Hi there,

Can someone help me understand where ‘records’, ‘id’, ‘prop’ and ‘value’ come from in Record Collection? Do you always use these exact names in a function like this one or can ‘records’ also be changed in ‘bikes’ for instance when not dealing with a record collection but a bike collection. How does one know that ‘2548’, ‘2468’, etc. is the [id]. I couldn’t find an example in previous lessons. Hope this make sense to you.

1 Like

Hey Remco, yet another why :slight_smile: keep em coming!

There are 2 things happening here, one is ‘use logical naming’ and the second is ‘we usually do things like this’.

It comes from a historical view on databases as well as the type of operation. Most programs that work on databases have so called ‘CRUD’ operations (create, read, update and delete). And to uniquely identify a record/row/tuple in a database usually an ID is use. This can be a sequential numbering method (which may have gaps when records are deleted) or something that is totally unique to that data (like a social security number). And in general this field is referred to as ID (must? no. usually? yes!) So in a dataset like the records collection, the unique number is ‘cleary’ the id).

Then the data, it is clearly stored in terms of property/value so it makes sense to name the parameters like that in the update function. But it depends on what is stored, and what you access if this should always be the case. It is so generic though, that this works for many situations. Another generic naming would be key/value. However if your data objects only holds specific things, like task title + status, you could have the function just as well read updateTask(tasks,taskid,title,status) and that would make perfect sense.

I hope that helps?

2 Likes