If you're seeing this message, it means we're having trouble loading external resources on our website.

# 复习：函数

``````var sayHello = function() {
};``````

``````var sayHello = function() {
text("你好!", random(200), random(200));
};``````

``sayHello();``

``````sayHello();
sayHello();
sayHello();``````

``````sayHello(50, 100);
sayHello(150, 200);``````

``````var sayHello = function(xPos, yPos) {
text("你好!", xPos, yPos);
};``````

``````var sayHello = function(x, y) {
text("你好!", x, y);
};``````

``````var sayHello = function(name) {
text("你好, " + name, random(200), random(200));
};``````

``````sayHello("Winston");
sayHello("Pamela");``````

``````var sayHello = function(name, x, y) {
text("你好" + name, x, y);
};``````

``sayHello("Winston", 10, 100);``

``````var addNumbers = function(num1, num2) {
var result = num1 + num2;
return result;
};

text(sum, 200, 200); // 显示 "7"``````

``````var addNumbers = function(num1, num2) {
var result = num1 + num2;
return result;
result = result * 2; // 笨笨哒!
};``````

``var biggerSum = addNumbers(2, 5) + addNumbers(3, 2);``

``var hugeSum = addNumbers(addNumbers(5, 2), addNumbers(3, 7));``

``````var addNumbers = function(num1, num2) {
var localResult = num1 + num2;
println("局部结果是：" + localResult);
return localResult;
};
println(localResult); // 哦不!``````

``````var globalResult;

var addNumbers = function(num1, num2) {
globalResult = num1 + num2;
println("全局结果：" + globalResult);
};