The big idea
A function in code is a little machine you can use again and again. An AI helper can explain it like a recipe card.
Some examples
- AI says: 'A function is like a peanut butter sandwich recipe.'
- Each time you call the function, you get a sandwich!
- It can show you a 'sayHi()' function that says hi.
- It shows how 'addNumbers(3, 4)' gives you 7.
Try it!
Ask AI to make a tiny function called 'cheer()' that prints 'Yay!' three times.
End-of-lesson check
15 questions · take it digitally for instant feedback at tendril.neural-forge.io/learn/quiz/end-explorers-ai-coding-AI-and-functions
What is a function in code?
- A type of computer game
- A reusable set of instructions that does a specific task
- A picture that shows on the screen
- A mistake that stops code from working
Why is a function compared to a recipe card?
- Both only work on tablet computers
- Both are only used once and then thrown away
- Both contain a set of instructions you can follow again and again
- Both require special cooking equipment to work
What does it mean to 'call' a function?
- To ask the computer to run the function's instructions
- To phone the function on a telephone
- To delete the function from the program
- To turn the function into a picture
If you have a function called 'sayHi()', what might it do?
- Make the computer say hello out loud
- Show a picture of a tiger
- Print or display the words 'hello' or 'hi'
- Delete all your files
What is the result of the function call 'addNumbers(3, 4)'?
- It returns the word 'three four'
- It returns the number 12
- It returns the number 7
- It deletes the numbers 3 and 4
Why do programmers use functions?
- To create more bugs on purpose
- To make their programs run slower
- To avoid writing the same code multiple times
- To hide their code from everyone
What would a function called 'cheer()' that prints 'Yay!' three times do?
- Display 'Yay! Yay! Yay!' on the screen
- Display 'Yay!' 100 times
- Not display anything at all
- Display 'Yay!' one time
If a function is like a peanut butter sandwich recipe, what is calling that function like?
- Writing a new recipe
- Making the sandwich using the recipe
- Throwing the recipe away
- Reading the recipe out loud
What makes a function different from regular code that isn't in a function?
- A function only works on one specific computer
- A function only works on certain days
- A function can be used any time you need it without rewriting it
- A function must be typed in every time you use it
What would happen if you called the same function five times in a program?
- The program would crash
- The function would be deleted
- The function's instructions would run five separate times
- The function would change each time
Which of these is the BEST description of a function?
- An error message that appears when code breaks
- A type of computer hardware
- A colorful picture on a website
- A reusable mini-program that does one specific job
What does the '()' after a function name like 'sayHi()' tell you?
- That this is a function being called or defined
- That the code has an error
- That the function name is finished
- That the function has been deleted
If you needed to say 'hello' in ten different places in your program, why would a function help?
- You'd have to type 'hello' ten times anyway
- You'd write the greeting code once and call the function ten times
- You'd need ten different computers
- You'd have to rewrite the greeting each time
What is an AI helper in the context of learning to code?
- A computer that replaces the programmer
- A game where you talk to artificial characters
- A tool that explains code concepts in simple ways
- A robot that writes all your code for you
Why is 'addNumbers(3, 4)' called with numbers inside the parentheses?
- To tell the computer to add more numbers later
- To give the function the numbers it needs to work with
- To delete the function
- To make the function stop working