scrimba
Create an RPG game - Rob Sutcliffe
Character Objects
Go Pro!Bootcamp

Bootcamp

Study group

Collaborate with peers in your dedicated #study-group channel.

Code reviews

Submit projects for review using the /review command in your #code-reviews channel

Character Objects
by
AboutCommentsNotes
Character Objects
by
Expand for more info
index.js
run
preview
console
// 1. convert monster and hero variables data into a monster and hero object
// 2. pass the whole object into the renderCharacter function
// 3. update renderCharacter function to accepts a single paramater that will be the object
// and use the attributes of the object for name, emoji etc...
const heroElementId = "hero";
const heroName = "Wizard";
const heroEmoji = "🧙";
const heroHealth = 60;
const heroDiceRoll = 6;

const monsterElementId = "monster";
const monsterName = "Spider";
const monsterEmoji = "️️🕷";
const monsterHealth = 10;
const monsterDiceRoll = 2;

function renderCharacter(elementId, name, emoji, health, diceRoll) {
document.getElementById( elementId).innerHTML =
`<div class="character">
<div class="name"> ${name} </div>
<div class="emoji"> ${emoji} </div>
<div class="health">health: <b> ${health} </b></div>
<div class="dice-container"><div class="dice"> ${diceRoll} </div></div>
</div>`;
}

renderCharacter(heroElementId, heroName, heroEmoji, heroHealth, heroDiceRoll);
renderCharacter(monsterElementId, monsterName, monsterEmoji, monsterHealth, monsterDiceRoll);
Console
/index.html
-2:23