xxxxxxxxxx
43
//Create and use an add() function that takes 2 numbers and adds them together.
let num1;
let num2;
let sum;
function setup() {
createCanvas(400, 400);
textFont("Source Code Pro");
textSize(20);
}
function draw() {
background(250)
add(66, 66);
show();
}
function add(num1, num2) {
sum = num1 + num2;
}
function show() {
text("66+66=" + sum, 100, 100)
}
//want to do something fancy, but failed
/*function draw() {
background(220);
print(this.num1,this.num2);
show();
}
function add (mouseIsPressed) {
this.num1=random (20,60);
this.num2=random (40,90);
this.sum=this.num1+this.num2;
}
function show () {
text("=", 100,100);
text(this.sum, 103,100);
}
*/