Task 10: Understanding JavaScript Functions with a Recipe Example
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β
Welcome to today's task on JavaScript Functions! Imagine you want to cook your favorite dish, but every time, you have to call your friend to ask for the recipe. Instead of repeating the same process, wouldn't it be easier to write it down once and use it whenever you need? That's exactly what a JavaScript function does! Let's dive in!
** Step 1: What is a Function?β
A function is like a recipeβitβs a set of instructions that performs a task. Once we write it, we can use it anytime!"
function makePasta() {
console.log("1. Boil water");
console.log("2. Add pasta");
console.log("3. Cook for 10 minutes");
console.log("4. Drain and serve!");
}
Now, to use the recipe, just call the function:
makePasta();
Output:β
- Boil water
- Add pasta
- Cook for 10 minutes
- Drain and serve!
Step 2: Functions with Parametersβ
What if we want to make different types of pasta? We can pass ingredients as parameters to our function!"
function makePasta(sauce) {
console.log("Boil water");
console.log("Add pasta");
console.log("Cook for 10 minutes");
console.log("Drain and mix with " + sauce + " sauce!");
}
Using the function with different ingredients:β
makePasta("Tomato");
makePasta("Alfredo");
makePasta("Pesto");
function makePizza() {
console.log("π Step 1: Roll the dough.");
console.log("π
Step 2: Spread the sauce.");
console.log("π§ Step 3: Add cheese and toppings.");
console.log("π₯ Step 4: Bake it in the oven.");
console.log("βοΈ Step 5: Slice and serve your yummy pizza!");
}
makePizza();
Using the function with different ingredients:β
function makePizza(topping) {
console.log("π Rolling the dough...");
console.log("π
Spreading the sauce...");
console.log("π§ Adding cheese and " + topping + "...");
console.log("π₯ Baking the pizza...");
console.log("π Your " + topping + " pizza is ready!");
}
makePizza("pepperoni");
makePizza("mushrooms");
makePizza("pineapple");
Lets make chicken Noodlesβ
function makeChickenNoodles() {
console.log("π³ Step 1: Heat the pan.");
console.log("π§ Step 2: Add oil, garlic, and onions.");
console.log("π Step 3: Add chopped chicken and cook it.");
console.log("π Step 4: Add noodles and mix well.");
console.log("π₯ Step 5: Add veggies and sauces.");
console.log("π₯ Step 6: Stir-fry everything together.");
console.log("β
Step 7: Serve your tasty Chicken Noodles!");
}
makeChickenNoodles();
Recap β What Did We Learn?β
Awesome! Today, we learned how to create and use functions, pass parameters, and make our code reusable!"
- β Functions save time by reducing repetition
- β We can pass different values to make functions flexible
- β Functions make code organized and easier to debug