t1a16 — PowerUp: Stateful Hero Energy Tracker

Date: ___________________   |   Assignment: Stateful Object Assignment

Assignment Prompt 1. Define a global object called myHero with properties: name ("Captain Code"), power (100), and comment ("Ready for training!").
2. Complete trainHero() to subtract power every time the training button is clicked.
3. Use if / else if / else conditions to update myHero.comment according to the remaining power.
4. When power reaches 0 or below, trigger an alert(), update the comment, and reset power to 100.
5. Use the button's onclick handler to call trainHero() and display the updated object inside myDiv01.

Hero Status

Hero Name
Captain Code
Power Level
100 / 100
Power Classification
High Power
Training Sessions
0
100%

Power remaining

Training Controls





Click the training button to begin! Initial Power: 100

Training History

Each training session is recorded below.

Training history:
Captain Code is ready for training!

Power Level Guide

These classifications are based on the hero's current power after training.

Reference: MDN — Working with JavaScript objects.

Extension Challenge

Add a second hero property called level. Increase it every time the hero completes five training sessions. Display the level in the status panel, and make sure resetting the hero also resets the level.