Hello, could someone assess my code?
I want to make sure that I’m doing the right thing.
Cheers,
Hey again, I’m hoping to give you not just an assessment for the task, but also some pointers that may help you in future work.
Random numbers
Your random function works nicely, and goes well with the approach you’re using to determine the upper bound by the array’s length, since the length value will always be 1 more than the last accessible index and your random function excludes the upper bound.
If you want to learn more about how to get numbers from given ranges, refer to Math.random() Examples
Selecting DOM elements
const section = document.querySelector('section');
This line works just fine, but I wanted to suggest that in the future you select DOM elements from JS using IDs rather than their tag name, this is because selecting by tag name either returns the first matching element, or a list of all matching elements and may not work the way you expect it depending on the context.
For example, if you had two section elements in this Codepen and you were trying to target the second one, that line wouldn’t work because it would select the first.
More here: Locating DOM elements using selectors
Functions with side effects
I see you’re both printing the result to the paragraph and the console. You don’t need to do both, and in most cases it is best to avoid doing more than one thing in a function to avoid side effects. You can read more about that here if you’re interested: What is a Pure Function? by Eric Elliott
Other than that, your pen seems to be doing what the tasks wants you to do, so good going!