Storing function results into an array

My code so far:

function mapDefiner(min, max) {
    return Math.floor(Math.random() * (max - min + 1)) + min;

const amountOfMaps = mapDefiner(10, 50);

function shotDefiner(min, max) {
    let result = Math.floor(Math.random() * (max - min + 1)) + min;
    return result;

var shotArray = [];

function shotsPerMap(){
    for (let x = 0; x < amountOfMaps; x++) {
       console.log (shotDefiner(1, 15));


This prints random numbers based upon the results from the amountOfMaps RNG.
how do I push these results onto an array for further manipulation? For some reason I cannot get it to work whatever I am trying. Can someone help me?

What have you tried to push the values into an array? I don’t see push used in your code, unless I’m missing it?

function shotsPerMap(){
    for (let x = 0; x < amountOfMaps; x++) {
        shotDefiner(1, 15);

But that didnt work

I don’t understand this part. shotDefiner doesn’t return an object, right?

There is a let called result in shotDefiner. I thought through this way I was able to push contents of result found in shotDefiner onto the array shotArray since the results were assigned to the let ‘result’

shotDefiner is a function though and shotDefiner() is a function call. The function call resolves to the return value.

You probably need to learn some basics about functions and return values.

I know how that works. I am working on an RNG out of which all of the results are not known beforehand. I don’t have any results beforehand since they are randomized but I want to know how to push them onto the array shotArray in this case directly after they’ve been generated.

If you know how that works, then you should know that shotDefiner().result is nonsense. You are not returning an object with the result property. You are returning a number.

I just don’t know which parameter from the function to actually push onto the array from the function. Can you help me with that?

Do you know what this function returns?

Parameters go into a function. They are not the output.

If you know what the return value of this function is and how return values work, then what you want is straightforward. If you don’t understand function calls and return values, then this is really hard.

function returnSomething(num) {
  let returnValue = num * num;
  return returnValue;

let returnedThing = returnSomething(5);

What is the returnedThing?

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.