Seksjon 3. Kapittel 9
single
Challenge: Power-up the Hero
Sveip for å vise menyen
Oppgave
Sveip for å begynne å kode
Create a factory function that generates custom power-ups for a hero. Each power-up should remember its own multiplier and apply it to a hero's base stat, demonstrating closure behavior by allowing the inner function to remember the multiplier provided to the outer function.
- Define an inner function inside
create_power_upthat takes a single argumentbase_statand multiplies it bymultiplier. - Return this inner function from
create_power_up. - Use
create_power_upto create two power-ups: one that doubles and one that triples a stat. - Apply these power-ups to a hero's
attackanddefensestats and print the results.
Løsning
Alt var klart?
Takk for tilbakemeldingene dine!
Seksjon 3. Kapittel 9
single
Spør AI
Spør AI
Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår