JavaScript JavaScript Loops, Arrays and Objects Tracking Multiple Items with Arrays Using For Loops with Arrays

Cynthia Smith
Cynthia Smith
8,031 Points

2_loop.js practice. I input the final answer, and I get an error in the console: randomList has already been declared

function random100() { return Math.floor(Math.random() * 100) + 1; }

function createRandomList() { let randomList = []; for (let i=0; i<10; i++) { randomList.push(random100()); } return randomList };

let myRandomList = createRandomList(); console.log(myRandomList);

for (let i=0; i < myRandomList.length; i++) { console.log('Item ' + i + ' in the array is ' + myRandomList[i]); }

1 Answer

John Gilmer
PRO
John Gilmer
Pro Student 1,806 Points

I tried out your code and no errors occurred.

Cynthia Smith
Cynthia Smith
8,031 Points

Ok. Thanks for checking it.