#Javascript Quiz - Sept 15
##Questions
- Make a
Person
constructor with attributes:name:string
,height:string
,age:number
,sleeping:boolean
.
function Person (name, height, age, sleeping){
this.name = name;
this.height = height;
this.age = age;
this.sleeping = true;
}
- Add prototype methods to
person
:eat
,sleep
, andwakeUp
. (Thesleep
andwakeUp
methods should togglesleeping
totrue/false
, andeat
should return an eating noise.)
Person.prototype.eat = function(){
console.log("crunch... CRUNCH!");
};
Person.prototype.sleep = function(){
this.sleeping = true;
};
Person.prototype.wakeUp = function(){
this.sleeping = false;
};
- Make a
Student
prototype that inherits fromperson
and has the additional attribute ofstudying:boolean
.
function Student (studying){
this.studying = true;
}
Student.prototype = new Person();
Student.prototype.constructor = Student;
- Add methods to
Student
calledstudy
, andstopStudy
to togglestudying
Student.prototype.student = function(studying){
this.study = function(studying){
if (studying === false){
this.studying = true;
}
};
this.stopStudy = function(studying){
if (studying === true){
this.studying = false;
}
};
};
- Override the
sleep
method onstudent
to only runsleep
ifstudying
isfalse
.
Student.prototype.sleep = function(studying){
if (studying === false){
this.sleep = true;
} else {
this.sleep = false;
}
};