A request worth keeping
Save a good request with blanks in it. Fill the blanks each time. A request with blanks is called a frame.
- The frame: "Write about ___ for ___. Keep it to ___."
- Fill the blanks: topic, reader, length.
- One call builds: "Write about the water cycle..."
- Same frame. New values each time.
Slide each blank below. One call builds the request.
Loading lab…
The rule
A saved request is a function. Its changing parts are parameters. One call assembles the whole request. Write it so other values can fill the blanks.
The frame with blanks is a function. Each blank is a parameter. A filled value is an argument.
`` function ask(topic, who, howLong) { let text = "Write about " + topic; text = text + " for " + who + ". Keep it to "; return text + howLong + "."; } ``
Here topic is the subject and who is the reader. howLong is the length.
Take ask("the water cycle", "Class 6", "half a page"). Line 2 makes text the words Write about the water cycle. Line 3 adds for Class 6. Keep it to after them. The return line adds half a page. and hands back the whole text.
So the call gives back one readable line:
Write about the water cycle for Class 6. Keep it to half a page.
The function must return the text. Only then can the calling line use it.