← Back to course
Code Crew G3 / Week 05 / Friday
5/6
Week 05 Β· Functions

Friday

// Steps with names

Friday: Mini-Project

Rocket is hungry. "I want one function that makes any lunch!" he says. "Sandwich, salad, or soup."

Raven thinks about it. "What do you notice? Each lunch needs different steps."

Nova hums softly. "Here is a hint. Give the function an input called kind. Then use IF and ELSE to pick the steps." Let's help them design the lunch function.

My Lunch Function

Design a MAKE_LUNCH function. It takes one input: 'kind' (sandwich, salad, soup).

Write at least one IF/ELSE branch inside the function.

function make_lunch(kind):
IF kind == 'sandwich': ___________________________
ELSE IF kind == 'salad': _________________________
ELSE IF kind == 'soup': __________________________
ELSE: ____________________________________________

Reflection

Lunch Function Check

FUNCTIONS WITH CHOICES
  • Read the question.
  • Tap your answer.
make_lunch(kind): IF kind is soup, heat a pot. ELSE get bread. What does make_lunch(soup) do?
What is the input in make_lunch(soup)?
Rocket calls make_lunch with soup, then salad, then soup. How many pots get heated?
Can a function have an IF inside it?
pack_bag(day): IF day is gym day, add sneakers. ELSE add a book. What does pack_bag(gym day) add?
What does pack_bag(art day) add?
pack_bag is called 5 times. Two are gym days. How many books get packed?
StatementTrue or false?
One function can do different things for different inputs.?
An input is written inside the parentheses.?
A function with an IF runs both paths every time.?
make_lunch(salad) heats a pot.?
WHY THIS EXERCISEInputs and IF rules make functions flexible.

Quick Check

In make_lunch(kind), IF kind is soup, it heats a pot. ELSE, it gets bread. What does make_lunch('salad') do? ____
WHY THIS EXERCISEFunctions can make decisions with IF and ELSE. The input picks which branch runs.
← Thursday