Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialanoncoding
2,534 PointsExample with Conditional (ternary) operator
class Pet {
constructor(animal, age, breed, sound) {
this.animal = animal
this.age = age
this.breed = breed
this.sound = sound
}
get activity() {
const today = new Date
const hour = today.getHours()
return hour > 8 && hour <= 20 ? "playing" : "sleeping"
}
speak() {
console.log(this.sound)
}
}
const vera = new Pet ("Dog", 7, "border collie", "Woof!")
console.log(vera.activity)
1 Answer
anoncoding
2,534 PointsHe Steven, thank you. The idea was only to show an example with ternary. Best regards
Steven Parker
231,268 PointsOh, I see. Good job.
Steven Parker
231,268 PointsSteven Parker
231,268 PointsThis code seems to function correctly, did you have a question about it?