Hướng dẫn thử thách
1 / 1
Build a Digital Pet Game
**Objective:** Fulfill the user stories below and get all the tests to pass to complete the lab.
**User Stories:**
The application should have two views. The requirements for each view are encompassed by the rest of the user stories:
The first view:
- Should contain a form that accepts a single string input.
- Should ask the user to name their pet.
- Should contain a button for submission that will start the game.
- Should disappear on submission.
The second view:
- Should appear upon submission of the first view.
- Should contain three `<button>` elements.
- Each button element should pertain to one each of the three following actions: `[EAT, PLAY, SLEEP]`.
- The `EAT` button should reduce the pets `Hunger` value, and increase the pets `Energy` value.
- The `PLAY` button should reduce the pets `Energy` value, and increase the pets `Happiness` value.
- The `SLEEP` button should increase the pets `Hunger` value, and increase the pets `Energy` value.
- Should visually track three properties of the pet. These are: `['Hunger', 'Happiness', 'Energy']`.
- Each element that tracks each of the three properties should:
- Contain the text relevant to that property, case insensitive, e.g., `hunger`, `Hunger`, `hUnGeR`, are all valid.
- NOT contain the text relevant to other properties, i.e., the `Hunger` tracking element must NOT contain the text `Happiness`.
- Contain a clear numeric representation of that properties current value.
- Each `Action` available to the pet should be encompassed by an enumerator.
- Each `Action` `button` should contain one each of the following `id`'s relevant to that button's action: `['eat-action', 'play-action', 'sleep-action']`.
- The pet should have the following moods, encompassed by a `PetMood` enumerator: `['Happy', 'Excited', 'Content', 'Sad', 'Tired', 'Sick', 'Hungry']`.
- The pet should be `Hungry` if `Hunger > 70`.
- The pet should be `Tired` if `Energy < 30`.
- The pet should be `Sad` if `Happiness < 30`.
- The pet should be `Excited` if `Happiness > 80` and `Energy > 70`.
- The pet should be `Happy` if `Happiness > 60`.
- Otherwise, the pet should be `Content`.
- The pet should have a number of images or emoji tied to each `Mood`.
- These emoji or images should be tied to the current `PetMood`, with a `Record`.
- The key of each `Record` entry should be the relevant `PetMood` enum value.
# --before-all--
```js
globalThis._PET_NAME = 'Fitzgerald';
globalThis._clock = __FakeTimers.install();
const _testCatFact = 'Cats sleep for around 13 to 16 hours a day.';
window.fetch = () =>
Promise.resolve({
ok: true,
status: 200,
statusText: 'OK',
json: () => Promise.resolve(_testCatFact),
text: () => Promise.resolve(JSON.stringify(_testCatFact))
});
```
# --after-all--
```js
globalThis._clock.uninstall();
delete globalThis._clock;
delete globalThis._PET_NAME;
```
Vượt qua bài kiểm tra hiện tại để mở khóa bài tiếp theo.
main.sh
UTF-8 • Tab Size: 2Kiểm tra bài:⌘↵