Provided that we use valid quote marks, it performs concatenation.
Try this:
function setup() {
createCanvas(400, 200);
frameRate(2);
textSize(24);
}
function draw() {
background(255);
// concatenate a string and a number
// perfectly legal in JavaScript
text("Frame " + frameCount, 10, height / 2);
}
Image:
However, the quote marks here do not look correct:
contador =‘contador’ + 1
console.log (‘contador’)
Concatenation is probably not what was needed there anyway.
SOME EDITS (March 27, 2021):
@xiquip, while we are are on the subject of counters, you may want to read p5.js Reference: frameCount
. Also perform a search on modulus. Those topics may be useful for what you are doing.
Also try this out, and see the embedded comments:
function setup() {
// the setup() function runs only once
createCanvas(300, 300);
noStroke();
rectMode(CENTER);
background(0, 0, 0); // black background
fill(255, 255, 255); // initialize fill as yellow
}
function draw() {
// the draw() function runs repeatedly
// frameCount starts at 0 in setup() and increments each time draw() runs
// we can sometimes use it as an alternative to maintaining a counter
// using modulus (remainder) operation for cyclical action
// % is the modulus operator, computes a remainder
if (frameCount % 300 === 0) { // remainder of 0
fill(255, 0, 0); // red fill
} else if (frameCount % 300 === 100) { // remainder of 100
fill(0, 255, 0); // green fill
} else if (frameCount % 300 == 200) { // remainder of 200
fill(0, 0, 255); // blue fill
}
rect(width/2, height/2, 250, 250);
}
The code might provide some ideas for the program with which you are currently working.