What I am trying to achieve in this code is to be able to console.log(createdAnimal) and then get the code to print out the objectAnimal with these parameters:
animalMaker('cat','flying',true);
It works when I invoke the animalMaker function, but I need it to work when I console.log(createdAnimal).
Thank you in advance!
Here is the code:
function animalMaker(inputType, inputSuperPower, inputCanFly){
var objectAnimal = {
'type': inputType,
'inputSuperPower': inputSuperPower,
'inputCanFly': inputCanFly,
'createdBy': 'Scotty'
};
console.log(objectAnimal)
}
var createdAnimal = animalMaker('cat','flying',true);
console.log(createdAnimal);
You need to return the object from the function:
function animalMaker(inputType, inputSuperPower, inputCanFly){
var objectAnimal = {
'type': inputType,
'inputSuperPower': inputSuperPower,
'inputCanFly': inputCanFly,
'createdBy': 'Scotty'
};
return objectAnimal;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With