Write a sketch that adds and removes elements from an array. Start with an empty array. If the user clicks on the left side of the screen, push a random number into the array. If the user clicks on the right side of the screen, pop the right most number off of the array (push and pop are always on the right side of the array).
At all times, display the contents of the array as a vertical list of numbers on screen using text() and textHeight() like you have before.
Start with an empty array like this:
var nums = [ ];
If the array is empty, display “Empty Array” instead of a number. The array is empty when the array length is 0.
When you add a random number to the array and display it, you will see a number with a long fractional part like this:
You might want to just deal with integers like 20 and 45. If so, wrap the call to random() with the int() function. That will convert the number to an integer: https://p5js.org/reference/#/p5/int
Like this: int(random(1,20));
Go back to Arrays 1