Skip to main content

Task 9: Creating Your Own JavaScript Function – Making a Sandwich & a Cup of Coffee

Start with Affirmation​

  • "I am destined for greatness. Every step I take brings me closer to my goals. I embrace challenges, knowing they are stepping stones to success. My mind is focused, my heart is determined, and my actions are aligned with my dreams."

Daily Affirmations for Success

  • βœ… I am capable, confident, and unstoppable.
  • βœ… Success flows to me because I take consistent action.
  • βœ… I attract opportunities that align with my purpose.
  • βœ… My hard work and persistence create abundance.
  • βœ… I am always learning, growing, and evolving.
  • βœ… I believe in my potential and trust my journey.
  • βœ… I turn setbacks into comebacks with resilience.
  • βœ… I am grateful for every success, big and small.

Success Reflection​

"Every effort I made today has planted seeds for my future success. I release any doubts and trust the process. My dreams are possible, and I am getting closer every day. I am grateful, I am strong, and I am ready for more!"

πŸ’ͺ Repeat daily, feel the power, and watch your success unfold!


πŸ”Ή If you don’t understand the task, watch the video above for the answer.


Task​

  • βœ… Understand how functions work in JavaScript
  • βœ… Write a function with steps to make a sandwich and coffee
  • βœ… Use parameters to customize your order

"Let’s get started!" πŸš€


** Step 1: Understanding Functions​

A function is like a recipe. You give it instructions, and it follows them to complete a task. Let’s create our first function for making a sandwich!"

function makeSandwich() {
console.log("Taking two slices of bread");
console.log("Adding lettuce, tomato, and cheese");
console.log("Closing the sandwich and serving!");
}

Now, we need to call the function to run it!

This will print step-by-step instructions for making a sandwich!" βœ…

makeSandwich();

Step 2: Making a Customizable Sandwich (Using Parameters)​

What if you want to choose different ingredients? We can use parameters to make a flexible sandwich function!

function makeSandwich(bread, filling, sauce) {
console.log(`Taking two slices of ${bread} bread`);
console.log(`Adding ${filling}`);
console.log(`Spreading some ${sauce}`);
console.log("Closing the sandwich and serving!");
}

Now, we can create different sandwiches by calling the function with different ingredients!

makeSandwich("wheat", "chicken & cheese", "mayo");
makeSandwich("white", "peanut butter & jelly", "honey");



Step 3: Making a Cup of Coffee Function​

Let’s create another function for making coffee

function makeCoffee(size, type, sugarAmount) {
console.log(`β˜• Preparing a ${size} cup of ${type} coffee`);
console.log(`πŸ₯„ Adding ${sugarAmount} teaspoons of sugar`);
console.log("πŸ”₯ Heating up water and brewing coffee");
console.log("β˜• Your coffee is ready to enjoy!");
}

Now, let’s customize our coffee!

makeCoffee("large", "espresso", 2);
makeCoffee("medium", "cappuccino", 1);

Recap – What Did We Learn?​

Awesome work! Today, we learned how to:

  • βœ… Create functions in JavaScript
  • βœ… Use parameters to customize our functions
  • βœ… Make both sandwiches and coffee using functions