Hello...i have a question.
How am i supposed to use the keywrod 'extends' in this JavaScript code
How am i supposed to use the keywrod 'extends' in this JavaScript code
Code:
let Books = {
author:'',
title:'',
pages: '',
isCheckedOut: false,
ratings: [],
getAverageRating: function () {
let total = 0;
for(var i in this.ratings){
total+=this.ratings;
}
console.log(total/this.ratings.length);
},
toggleCheckOutStatus: function ()
{
if (this.isCheckedOut == false)
{
return this.isCheckedOut = true;
}
else
{
return this.isCheckedOut;
}
},
addRating: function () {
let add = parseInt(prompt('Add rating!'));
for (let i = 1; i <= 5; i++) {
if (add > 5 || add < 1)
{
add = parseInt(prompt('The rating must be between 1 and 5'));
}
else
{
this.ratings.push(add);
}
}
},
get getAuthor()
{
let author1 = prompt('Enter a name!');
return author1;
},
get getTitle()
{
let title1 = prompt('Enter a title!');
return title1;
},
get getPages()
{
let pages1 = parseInt(prompt('Enter a number of pages!'));
return pages1;
}
}
let Movies = {
director:'',
title:'',
runTime:'',
isCheckedOut: false,
raitings: [],
getAverageRating: function () {
let total = 0;
for(var i in this.ratings){
total+=this.ratings;
}
console.log(total/this.ratings.length);
},
toggleCheckOutStatus: function ()
{
if (this.isCheckedOut == false)
{
return this.isCheckedOut = true;
}
else
{
return this.isCheckedOut;
}
},
addRating: function () {
let add = parseInt(prompt('Add rating!'));
for (let i = 1; i <= 5; i++) {
if (add > 5 || add < 1)
{
add = parseInt(prompt('The rating must be between 1 and 5'));
}
else
{
this.ratings.push(add);
}
}
},
get getDirector()
{
let director1 = prompt('Enter a name!');
return director1;
},
get getTitle()
{
let title1 = prompt('Enter a title!');
return title1;
},
get getRunTime()
{
let runTime1 = parseInt(prompt('Enter a run time!'));
return runTime1;
}
}
Last edited by a moderator: