Published
Edited
Feb 26, 2020
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
/* class declaration */ class Doggo {
//constructor:
constructor(name, vegetarian) {
this.species = 'doggo';
this.fluffy = true;
this.talk = 'woooof';
this.name = name;
this.vegetarian = vegetarian;
}

//method:
introduce() {
if (this.vegetarian)
return 'Hai, my name is ' + this.name + ' and I am a vegetarian';
else return 'Hai, my name is ' + this.name + ' and I am not a vegetarian';
}
}
Insert cell
Insert cell
clifford = new Doggo('Clifford', false)
Insert cell
clifford.introduce()
Insert cell
veggie = new Doggo('Veg', true)
Insert cell
veggie.introduce()
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
class Hooman {
constructor (faveFood, likesHickey, doesAnythingButEat, gender, nerd) {
this.species = 'Hooman';
this.faveFood = faveFood;
this.likesHickey = likesHickey;
this.doesAnythingButEat = doesAnythingButEat;
this.gender = gender;
this.readsBioTextbooksForFun=false;
this.nerd = nerd;
if (nerd) {
this.tellsProfsThatTheyReadTextbooksForFunWhenAsked = true;
} else {
this.tellsProfsThatTheyReadTextbooksForFunWhenAsked = false
}
}

eatFood(food) {
if (!this.doesAnythingButEat) {
return 'Yum, I want some more (OM NOM NOM NOM)';
}
else if (food === 'Hickey' && !this.likesHickey) {
return 'Food Poisoning';
}
else {
return `Om nom nom... I'm stuffed!`;
}
}
readBook(isTextbook, professorWatching, quality) {
if (quality === 'super') {
this.readsBioTextbooksForFun = true;
return 'Wow, I might actually keep reading this to learn (*gasp*)';
} else if (quality === 'snooozeville') {
this.readsBioTextbooksForFun = false;
return 'ZZZZzzzzzzzzzzzzzzz';
} else if (isTextbook && professorWatching && this.tellsProfsThatTheyReadTextbooksForFunWhenAsked) {
return "Shhh... I'm reading here!";
} else {
return 'Who needs this textbook anyway? I should Snap instead';
}
}
doMath(num1, num2) {
return num1 + num2;
}
}
Insert cell
Insert cell
Insert cell
Insert cell
class Kitty {
constructor (name, breed, color){
this.name =name;
this.color=color;
this.breed = breed;
}
changeAttr(){
if(this.breed="ginger"){
return "ginger"
}
else{
return "simese"
}
}
kittyPower(){
if(this.color="red"){
return this.color
}
}
}
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more