xxxxxxxxxx
29
/*
Objective:
- Loops and arrays
*/
let vehicles = ['🚗','🚌','🚑','🚛'];
function setup() {
createCanvas(400, 400);
}
function draw() {
background(255);
textSize(50);
// We can access the items in the array by using the [] notation. We include the position (index) of the item we want. vehicles[0] returns '🚗'
for(let i = 0; i < vehicles.length; i++){
text(vehicles[i], i * 50, 200)
}
}
function keyPressed(){
if(key === 'a'){
vehicles.push('🚲');
}
if(key === 'd'){
vehicles.pop();
}
}