Loop through function names

im coding on codepen and its seems the loop only shows the first element of the array. Thanks in advance, Here is the code:

let moves = [lighting, fire];

function lighting() {

};

function fire() {

};

function myFunction (){
for (let i = 0; i < moves.length; i++) {
return moves[i].name;
}
}

console.log(myFunction());

Why do you think is causing only a single iteration? Please think about it before continue reading

a return keywords means returning/handing back data to the caller. Just like when you hand some back in real life (a questionnaire, an exam). Once you hand it in, the task is done. Same here, return will signal that the function is done executing.

right i see i understand. However its returning undefined when i have taken out the return keyword. Why is that?

that also make sense? If you don’t return anything, yet you attempt to log what is returned:

console.log(myFunction()); 

you get undefined.

The question is: What are you trying to here? And why? Do you need to return something? Why or why not?

Im trying to log all the function names into the console. Trying to make simple rpg battle system. The functions are the names of the moves. You then pick a move from the array. I used a array because i want to change in and out different moves. The funny thing is i did this months ago and got it to work. But cant remember now…

Then the objective is pretty clear? You should .log() within your loop.

Consistant practice is highly recommend with programming.

Thank you it worked. Yeah your right, i need to stop having breaks…Thanks again.