Published
Edited
Feb 18, 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 {
constructMe(faveFood, likesHickey, doesAnythingButEat, gender, nerd) {
this.species = 'Hooman';
faveFood = faveFood
this.likesHickey = this.likesHickey;
this.doesAnythingButEat = doesAbsolutelyAnythingButEat;
this.gender = gender;
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 (this.food === 'Hickey' && !this.likesHickey) {
return 'Food Poisoning';
else {
return `Om nom nom... I'm stuffed!`;
},
this.readBook(isTextbook professorWatching quality) {
return
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 &
tellsProfsThatTheyReadTextbooksForFunWhenAsked
) {
`Shhh... I'm reading here!`;
} else {
return 'Who needs this textbook anyway? I should Snap instead';
}
},
Hooman.doMath(num1, num2) {
return num1 + num2;
}
}
Insert cell
Insert cell
Insert cell
Insert cell
class Kitty {
//code here
}
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