lundi 20 juin 2022

Array of functions not working when called in object

So I'm working on what should have been an easy project but is giving me, my classmates, and my mentor a ton of headaches. We're nearly there but it's still missing one piece to finally wrap it up. I just need to get the fact area to fill out with one of the function options.

Here's the function:

function createHuman(){
  let height = parseInt(humanFeet) * 12 + parseInt(humanInches);
    debugger
    myNewHuman = new human(humanName, "human", humanWeight.value, height, humanDiet.value, compareRand);
    function compareWeight(humanWeight){
      let myRandNum = Math.floor(Math.random() * dinoArr.length);
      let myMessage = `You are ${dinoArr[myRandNum].weight - humanWeight} pounds lighter than a ${dinoArr[myRandNum].name}.`;
      return myMessage;
      };
    function compareHeight(height){
      let myRandNum = Math.floor(Math.random() * dinoArr.length);
      let myMessage = `You are ${dinoArr[myRandNum].height - height} pounds shorter than a ${dinoArr[myRandNum].name}.`;
      return myMessage;
      };
    function compareDiet(humanDiet){
      let myRandNum = Math.floor(Math.random() * dinoArr.length);
      let myMessage = `You're a ${humanDiet} while ${dinoArr[myRandNum].name} is a ${dinoArr[myRandNum].diet}.`;
      return myMessage;
      };
  const compareRand = Math.floor(Math.random() * compareArray.length);
  compareArray = [compareWeight(), compareHeight(), compareDiet()]; 
};

Individually the functions work fine when placed like this , compareWeight(humanWeight.value) where compareRand is right now and the results should look like this: Screenshot of example of one function working in the facts area. I would post a screenshot of all the dinos around the human tile but that's too big for stackoverflow.

I'd really appreciate any input anyone could give me so I can finally finish is project.

(Please note: the dinoArr is an array outside of this function pulling data from a .json file. As the screenshot shows it's pulling the data just fine I just need to get the random picking of the array of functions to work.)




Aucun commentaire:

Enregistrer un commentaire