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'm a vegetarian!`
}
else {
return `Hai, my name is ${this.name} and I'm definately 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
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

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more