Meal Maker Project - JavaScript Objects

Hey all!

Really happy to have completed the meal maker project without too many issues!
Here is my code

Any feedback that may make the code tidier or more readable would be greatly appreciated.


First and foremost, nicely done :slight_smile:

Few small points, within the addDishToCourse I would very likely do:

console.log(`${courseName} is not a valid course, please enter a valid course name`);

this makes it easier to track which course goes is invalid. Maybe even list the valid choices?

And I would personally prefer:

  invalidateCourse(name) {
    return !Object.keys(this).includes(name);
  addDishToCourse(courseName, dishName, dishPrice) {
    if (this.invalidateCourse(courseName)){
       console.log('Please Enter a valid course name');
    const dish = {
      name: dishName,
      price: dishPrice,
    this[courseName] = dish;

two things I did here:
gave addDishToCourse one responsibility, not two. Makes it easier if you write test cases.
I like to deal with errors/problems first, just a style preference.

1 Like

Thanks for the feedback - it’s a great help.

When you refer to limiting the responsibilities of functions/methods, how would I determine if an expression would serve better within a helper function or as written within the main function?

1 Like

A function or method should only serve a single purpose. In your case, addDishToCourse was doing two things:

  1. validating the courseName
  2. adding the course

that is (ideally) when you need to separate functionality.

That makes perfect sense, thanks!

I seem to have little issue with understanding the concepts, it’s just cleaning up my code and adhering to best practices that I would love to improve on.

Much appreciated

1 Like

this takes time and practice, working on projects and gaining experience helps a lot. Also studying other peoples code helps, or work along people on the same project