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!
Task Answer - Video Linkβ
πΉ 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