Files
.github
api-server
client
config
curriculum
__fixtures__
challenges
_meta
chinese
english
01-responsive-web-design
02-javascript-algorithms-and-data-structures
basic-algorithm-scripting
basic-data-structures
basic-javascript
basic-javascript-rpg-game
part-001.md
part-002.md
part-003.md
part-004.md
part-005.md
part-006.md
part-007.md
part-008.md
part-009.md
part-010.md
part-011.md
part-012.md
part-013.md
part-014.md
part-015.md
part-016.md
part-017.md
part-018.md
part-019.md
part-020.md
part-021.md
part-022.md
part-023.md
part-024.md
part-025.md
part-026.md
part-027.md
part-028.md
part-029.md
part-030.md
part-031.md
part-032.md
part-033.md
part-034.md
part-035.md
part-036.md
part-037.md
part-038.md
part-039.md
part-040.md
part-041.md
part-042.md
part-043.md
part-044.md
part-045.md
part-046.md
part-047.md
part-048.md
part-049.md
part-050.md
part-051.md
part-052.md
part-053.md
part-054.md
part-055.md
part-056.md
part-057.md
part-058.md
part-059.md
part-060.md
part-061.md
part-062.md
part-063.md
part-064.md
part-065.md
part-066.md
part-067.md
part-068.md
part-069.md
part-070.md
part-071.md
part-072.md
part-073.md
part-074.md
part-075.md
part-076.md
part-077.md
part-078.md
part-079.md
part-080.md
part-081.md
part-082.md
part-083.md
part-084.md
part-085.md
part-086.md
part-087.md
part-088.md
part-089.md
part-090.md
part-091.md
part-092.md
part-093.md
part-094.md
part-095.md
part-096.md
part-097.md
part-098.md
part-099.md
part-100.md
part-101.md
part-102.md
part-103.md
part-104.md
part-105.md
part-106.md
part-107.md
part-108.md
part-109.md
part-110.md
part-111.md
part-112.md
part-113.md
part-114.md
part-115.md
part-116.md
part-117.md
part-118.md
part-119.md
part-120.md
part-121.md
part-122.md
part-123.md
part-124.md
part-125.md
part-126.md
part-127.md
part-128.md
part-129.md
part-130.md
part-131.md
part-132.md
part-133.md
part-134.md
part-135.md
part-136.md
part-137.md
part-138.md
part-139.md
part-140.md
part-141.md
part-142.md
part-143.md
part-144.md
part-145.md
part-146.md
part-147.md
part-148.md
part-149.md
part-150.md
part-151.md
part-152.md
part-153.md
debugging
es6
functional-programming
functional-programming-spreadsheet
intermediate-algorithm-scripting
intermediate-javascript-calorie-counter
javascript-algorithms-and-data-structures-projects
object-oriented-programming
regular-expressions
03-front-end-libraries
04-data-visualization
05-apis-and-microservices
06-quality-assurance
07-scientific-computing-with-python
08-data-analysis-with-python
09-information-security
10-coding-interview-prep
11-machine-learning-with-python
12-certificates
schema
test
.babelrc
LICENSE.md
comment-dictionary.js
create-challenge-bundle.js
getChallenges.acceptance.test.js
getChallenges.js
getChallenges.test.js
gulpfile.js
lib.js
package-entry.js
package-lock.json
package.json
utils.js
cypress
docs
tools
utils
.editorconfig
.eslintignore
.eslintrc.json
.gitattributes
.gitignore
.gitpod.yml
.node-inspectorrc
.npmrc
.prettierignore
.prettierrc
.snyk
.vcmrc
CODE_OF_CONDUCT.md
CONTRIBUTING.md
Dockerfile.tests
HoF.md
LICENSE.md
README.md
SECURITY.md
change_volumes_owner.sh
crowdin.yml
cypress-install.js
cypress.json
docker-compose-shared.yml
docker-compose.tests.yml
docker-compose.yml
jest.config.js
lerna.json
lighthouserc.js
package-lock.json
package.json
sample.env

212 lines
4.8 KiB
Markdown
Raw Normal View History

---
id: 5d65f6392012114c7d7c57ed
title: Part 20
challengeType: 0
---
## Description
<section id='description'>
When a player clicks the 'Go to store' button, the buttons and text in the game should change.
Remove the code inside the `goStore` function. Add a new line of code inside the function that updates the text of `button1` so that it says "Buy 10 health (10 gold)".
For example, this code updates the text of `button` to say "Click Me": `button.innerText = "Click Me";`.
</section>
## Instructions
<section id='instructions'>
</section>
## Tests
<section id='tests'>
```yml
tests:
- text: See description above for instructions.
# testString: assert(goStore.toString().match(/button1\.innerText\s*\=\s*[\'\"\`]Buy 10 health \(10 gold\)\.?[\'\"\`]/));
testString: assert((() => { goStore(); return button1.innerText === "Buy 10 health (10 gold)" })());
```
</section>
## Challenge Seed
<section id='challengeSeed'>
<div id='html-seed'>
```html
<script>
let xp = 0;
let health = 100;
let gold = 50;
let currentWeapon = 0;
let fighting;
let monsterHealth;
let inventory = ["stick"];
const button1 = document.querySelector('#button1');
const button2 = document.querySelector("#button2");
const button3 = document.querySelector("#button3");
const text = document.querySelector("#text");
const xpText = document.querySelector("#xpText");
const healthText = document.querySelector("#healthText");
const goldText = document.querySelector("#goldText");
const monsterStats = document.querySelector("#monsterStats");
const monsterNameText = document.querySelector("#monsterName");
const monsterHealthText = document.querySelector("#monsterHealth");
// initialize buttons
button1.onclick = goStore;
button2.onclick = goCave;
button3.onclick = fightDragon;
function goStore() {
console.log("Going to store.");
}
function goCave() {
console.log("Going to cave.");
}
function fightDragon() {
console.log("Fighting dragon.");
}
</script>
```
</div>
### Before Test
<div id='html-setup'>
```html
<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="UTF-8">
<title>RPG - Dragon Repeller</title>
<style>
body {
background-color: darkblue;
}
#text {
background-color: black;
color: white;
padding: 10px;
}
#game {
max-width: 500px;
max-height: 400px;
background-color: lightgray;
color: white;
margin: 0 auto;
padding: 10px;
}
#controls {
border: 1px black solid;
padding: 5px;
}
#stats {
border: 1px black solid;
color: black;
padding: 5px;
}
#monsterStats {
display: none;
border: 1px black solid;
color: white;
padding: 5px;
background-color: red;
}
.stat {
padding-right: 10px;
}
</style>
</head>
<body>
<div id="game">
<div id="stats">
<span class="stat">XP: <strong><span id="xpText">0</span></strong></span>
<span class="stat">Health: <strong><span id="healthText">100</span></strong></span>
<span class="stat">Gold: <strong><span id="goldText">50</span></strong></span>
</div>
<div id="controls">
<button id="button1">Go to store</button>
<button id="button2">Go to cave</button>
<button id="button3">Fight dragon</button>
</div>
<div id="monsterStats">
<span class="stat">Monster Name: <strong><span id="monsterName"></span></strong></span>
<span class="stat">Health: <strong><span id="monsterHealth"></span></strong></span>
</div>
<div id="text">Welcome to Dragon Repeller. You must defeat the dragon that is preventing people from leaving the town. You are in the town square. Where do you want to go? Use the buttons above.</div>
</div>
```
</div>
### After Test
<div id='html-teardown'>
```html
</body>
</html>
```
</div>
</section>
## Solution
<section id='solution'>
```html
<script>
let xp = 0;
let health = 100;
let gold = 50;
let currentWeapon = 0;
let fighting;
let monsterHealth;
let inventory = ["stick"];
const button1 = document.querySelector('#button1');
const button2 = document.querySelector("#button2");
const button3 = document.querySelector("#button3");
const text = document.querySelector("#text");
const xpText = document.querySelector("#xpText");
const healthText = document.querySelector("#healthText");
const goldText = document.querySelector("#goldText");
const monsterStats = document.querySelector("#monsterStats");
const monsterNameText = document.querySelector("#monsterName");
const monsterHealthText = document.querySelector("#monsterHealth");
// initialize buttons
button1.onclick = goStore;
button2.onclick = goCave;
button3.onclick = fightDragon;
function goStore() {
button1.innerText = "Buy 10 health (10 gold)";
}
function goCave() {
console.log("Going to cave.");
}
function fightDragon() {
console.log("Fighting dragon.");
}
</script>
```
</section>