Look at your code.
You pass a value to the function
- but you don't use it!
You only call
directly from within itself - but after the
line which exits the function immediately. So it is never called except from the
If you take out the
line it then recursively calls itself from itself ten times! And each of those calls itself 10 times, and each of those ... until the stack runs out.
Create two functions: one is called from the onClick event (call it RepeatNTimes), and it calls the other as many times as the user puts in the input box (call it CountIndex).
Test it, and make sure it works - it won't do what you need for the whole project, but this makes sure the framework is there.
Then modify RepeatNTimes: make it clear your arr array to all zeros before it calls CountIndex. Make sure that works.
Then modify it again show the values of arr in your reN.textContent display and make sure that works.
Now modify CountIndex to generate a random number and increment the appropriate element of arr by using that random value as an index.
Test it again.
This is development: a little step, a test, a fix, a text, a fix a test - then another little step, each building on the existing code when you know it works.
What you have looks like you threw it together without thinking about what it should do but with a lot of hope that you'd get lucky and it would just work! :laugh:
Also, see here: How to Write Code to Solve a Problem, A Beginner's Guide
But I'm not going to give you the code for this - it's your homework, and you need to learn how to do this for yourself!