Check your understanding of the previous reading: recognising function and method calls, and predicting the results of calling functions and methods with arguments.
How would you call a function named openDoor? Assume it takes no arguments.
A function call needs the function's name immediately followed by parentheses. Since openDoor takes no arguments, the parentheses stay empty: openDoor().
The function makeCat below returns the string "Cat". What value will the variable x hold after this line runs?
x = makeCat() + makeCat() + makeCat()
Each call to makeCat() is replaced by the string "Cat". The + operator on strings concatenates them, so "Cat" + "Cat" + "Cat" evaluates to "CatCatCat".
The function add5 below returns the number 5 added to its argument. What value will the variable x hold after this line runs?
x = add5(10) * add5(2)
add5(10) returns 15, and add5(2) returns 7. Multiplying them: 15 * 7 = 105.