xxxxxxxxxx
38
/*
Objectives:
- Learn Arrays.
- Declare variables with const. Difference between const and let.
- Event listeners
*/
// This code creates a list of elements. The list is of length 11.
const emojis = ['🤖','🦄','👾','🐶','🐰','🐳','🍄','🌍','🍉','🍕','🍭'];
// We access the first element on the emojis array at position zero (0).
let chosen = emojis[0];
function setup() {
createCanvas(400, 400);
}
function draw() {
background(255);
textSize(200);
textAlign(CENTER, CENTER);
text(chosen, width/2, height/2);
}
// this function is provided by p5. It creates an event listener that is enabled when the mouse is clicked.
function mouseClicked(){
let randomIndex = floor(random(emojis.length-1));
chosen = emojis[randomIndex];
console.log(randomIndex)
}
/*
CHALLENGES
1. Research and implement ways to add elements to the array.
2. Research and implement ways of removing elements from the array.
3. Research and implement how to join to arrays
*/