this is my second attempt at this question, hopefully, I can be a little clearer as to my problem. I have an initial p5.js setup:
// Setup empty array (I beleive 'position' this is in the global scope?)
let position = []
//p5 setup
function setup(){
createCanvas(400,400)
// Simple for loop to create an array of floating random numbers between 5 and 10 using the p5.js random function
for(let i = 0; i < 10 ; i++){
let x = random(5,10)
position.push(x)
}
}
function draw(){
background(100)
text(`This is the implementation of random ${random(5,10)`,10,10)
}
// Loging position unless I am mistaken, does NOT show the array
console.log(position)
// But trying to access an specific value within the array gives an 'undefined'
console.log(position[1])
// Undefined
How would I access an individual value?
let position = []
function setup() {
createCanvas(400, 400);
for (let i = 0; i < 10; i++) {
let x = random(5, 10)
position.push(x)
}
}
console.log(`The position array is ${position}`)
console.log(`The length of the position array is ${position.length}`)
console.log(`The second value in the position array is ${position[1]}`)
function draw() {
background(200)
text(`This is the implementation of random ${random(5,10)}`,10,10)
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.5.16/p5.js"></script>