Test your skills: Functions revision

See the Pen JavaScript: Funciones 1 by lTakisl (@ltakisl) on CodePen.

See the Pen JavaScript: Funciones 2 by lTakisl (@ltakisl) on CodePen.

See the Pen JavaScript: Funciones 3 by lTakisl (@ltakisl) on CodePen.

I have a separate query, as I progress through the different topics in some under the conclusion it says ‘see also’ that means that I have to study that before moving on to the following? Or after completing the entire syllabus, do I start to read the ‘see also’ of each topic to complement what I have studied? or is it indistinct? because if I start to see the ‘see also’ of each topic it leads to many ramifications and I end up making a mess since I end up reading things that I have not the remotest idea and I end up losing the thread.
That’s why I’m not even reading them at the moment.
Does it affect me at all?

Hello @Takis

you doing great well done just notice about task 3:

  1. for first step it ask for Refactor the code that generates the random number into a separate function called random(), which takes as parameters two generic bounds that the random number should be between, and returns the result.
    so the random method should take 2 parameter min and max and it return a random number based on those 2 values after that you use this method result to get the value from the array

  2. step 2 ask for Update the chooseName() function so that it makes use of the random number function, takes the array to choose from as a parameter (making it more flexible), and returns the result. so the this function should take 1 parameter which is the array and return the array element using the result of the random method

for the read also part it give your more reference to the same topic to learn more about it for example do you know that you can write for loop like that for(;true;) and there many variation to that so in my humble opinion it good to read them
when you read them you will see some repeated stuff that you already know from the lesson so you can read it faster and then focus on the new info

hope that help and have a nice day :slight_smile:

1 Like

I tried exercise 3 again and this is what came out. I got to the result, but I don’t know if what I did is as requested. I get lost in the slogans.
If I did it wrong, please tell me how I should have done it. Thank you.

See the Pen JavaScript: Funciones 3.0 by lTakisl (@ltakisl) on CodePen.

you very close well done @Takis

for the random function
it should return num not array[num];
so it be like that

function ramdon (min, max) {
  let num= Math.floor(Math.random() * (max - min)) + min;
  return num;
}

for choose name it should call the random and take the result to be the index of the element in the array that it will be return it
so

function chooseName(array){
    return array[ramdon(0, array.length)]; // 0 cause the array index start from 0 and the max will be the array.length as random will return value from min to max -1
}

then update this function caller so

para.textContent=chooseName(names);

hope that help and have a nice day :slight_smile: