s27 Answers
s27 Answers
/*
Important note: Don't pass the arrays as an argument to the function. The
functions must be able to manipulate the current arrays.
*/
/*
function addPokemon(pokemon){
registeredPokemon.push(pokemon);
}
console.log(registeredPokemon);
/*
2. Create a function called deletePokemon which will delete the last pokemon
you have added in the registeredPokemon array.
- If the registered is not empty, delete the last pokemon in the
registeredPokemon array
- Else return a message:
- "No registered pokemon."
- Invoke the function.
- Outside the function log the friendsList array.
*/
function deletePokemon(){
registeredPokemon.pop();
} else {
return "No pokemon registered"
}
};
console.log(registeredPokemon);
/*
3. Create a function called displayNumberOfPokemons which will display the amount
of registeredPokemon in our array,
- If the registeredPokemon array is empty return the message:
- "No pokemon registered."
- Else If the registeredPokemon array is not empty, return the number of
registered Pokemons.
*/
function displayNumberOfPokemons(){
if(registeredPokemon.length > 0){
return registeredPokemon.length
} else {
return "No pokemon registered"
}
}
console.log(registeredPokemon);
/*
4. Create a function called sortPokemon which will sort the registeredPokemon
array in alphabetical order when invoked:
- If the registeredPokemon array is empty return the message:
- "No pokemon registered."
- Else, sort the registeredPokemon array.
*/
function sortPokemon(){
};
console.log(registeredPokemon);
/*
5. Create a function called registerTrainer which takes 3 arguments, name,
level and an array of pokemons.
- Inside the function, create an object called trainer.
- The trainer object should have 3 properties, trainerName,
trainerLevel and pokemons
- Pass the values of the appropriate parameter to each property.
- Add the trainer variable to the registeredTrainers array.
*/
function registerTrainer(name,level,pokemons){
let trainer = {
trainerName: name,
trainerLevel: level,
pokemons: pokemons
}
registeredTrainers.push(trainer);
};
console.log(registeredTrainers);
}
} catch(err){