scrimba
Create an RPG game - Rob Sutcliffe
Adding methods and attributes
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

Adding methods and attributes
by
AboutCommentsNotes
Adding methods and attributes
by
Expand for more info
index.js
run
preview
console
const book = {
id: 1,
emoji: "📗",
author: "George Orwell",
title:"1984",
format:"Paperback",
price:"$9.99",
getTemplate: function() {
const { id, emoji, title, author, format, price} = this;
return `<div class="book">
<div class="emoji">${emoji}</div>
<div class="title">${title}</div>
<div class="author">${author}</div>
<div class="format">${format}</div>
<div class="price">${price}</div>
<button id="cart-${id}">Add to Cart</button>
</div>`
}
}



document.getElementById("books").innerHTML = book.getTemplate();

// update the title and the author of the book when the button is clicked
// note you will need to rerun the getTemplate method once it's updated
document.getElementById(`cart-${book.id}`).onclick = function() {



};
Console
/index.html
-1:36