The value it hands back
Printing an answer and returning it look the same on screen. Returning hands the answer back to the line that called the function.
ticketFare(3). The 3 goes in.ticketFare(3). The 3 goes in.- The body works out 8.
returnsends 8 back out.- A print-only body hands back nothing.
Slide the stops below. Compare the two boxes called due.
Loading lab…
The rule
`` function ticketFare(stops) { let full = 2 + 2 * stops; if (full > 12) { return 12; } return full; } ``
The if line limits the fare to 12. For 3 stops, full is 2 + 2 × 3 = 8. That is not above 12, so the first return is skipped.
ticketFare(3) runs, reaches return full, and becomes 8.
return hands one value back to the line that called it. That line becomes the value. A function that only prints puts a line on the screen. It hands back nothing.
let due = ticketFare(3); stores 8 in due. With a print-only body, due holds nothing. That is the value null, which means no value.