Hello!! I have done functions skill tests. Could you please assess them?
Function1:
Function2:
Function3:
Function4:
Hi, I am also learning js, and I just finished functions skills test.
I just want to share my experience.
On the first task, I think that you could put [Math.floor(Math.random() * names.length)] in a variable. So you could write something like this.
const i = Math.floor(Math.random() * names.length);
para.textContent = names[i];
but result is still same.
On the second task, my function is basically same as yours.
On the third task, I think in your random(min, max) function, max value cannot be generated.
On the second function of this task, I think that instead of 2, you should write 0, so every name is included. Also, arr.length as max is fine. Because your random(min, max) function can not generate max value.
I want to share my code, too.
function randomNumberGeneratorWithRange (min, max) {
return Math.floor(Math.random() * (max - min + 1) + min);
}
function chooseName(array) {
const i = randomNumberGeneratorWithRange(0, array.length-1);
const randomName = array[i];
return randomName;
}
Because of +1 in my function randomNumberGeneratorWithRange (min, max), It can generate max value. That is why I included in second function array.length-1 as max value.
My forth task function is also same as yours.
I hope I was helpful.
It does help me and I now see it from different aspect. Thanks!!