scrimba
Create an RPG game - Rob Sutcliffe
Deconstruct Characters Object
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

Deconstruct Characters Object
by
AboutCommentsNotes
Deconstruct Characters Object
by
Expand for more info
index.js
run
preview
console
// deconstruct the data at the top of the renderCharacter function
// use the new deconstructed variables throught the renderCharacter function

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


const hero = {
elementId: "hero",
name: "Wizard",
emoji: "🧙",
health: 60,
diceRoll: 6
}

const monster = {
elementId: "monster",
name: "Spider",
emoji: "🕷",
health: 10,
diceRoll: 2
}


renderCharacter(hero);
renderCharacter(monster);
Console
/index.html
-1:37