From c8fa471ecba0c65b26780c80d3503679c78a3826 Mon Sep 17 00:00:00 2001 From: Moataz Samir <47303454+moataz9@users.noreply.github.com> Date: Thu, 16 Feb 2023 16:04:06 +0200 Subject: [PATCH] Update solution.md Update "Why are both hamsters full?" removing stomach: [] and only create if we call eat() in corresponding objects and add items to it. --- .../4-hamster-proto/solution.md | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/1-js/08-prototypes/01-prototype-inheritance/4-hamster-proto/solution.md b/1-js/08-prototypes/01-prototype-inheritance/4-hamster-proto/solution.md index c141b2ecdc..3056ea244b 100644 --- a/1-js/08-prototypes/01-prototype-inheritance/4-hamster-proto/solution.md +++ b/1-js/08-prototypes/01-prototype-inheritance/4-hamster-proto/solution.md @@ -16,12 +16,15 @@ Please note that such thing doesn't happen in case of a simple assignment `this. ```js run let hamster = { - stomach: [], - +*!* + // stomach: [], (*) +*/!* eat(food) { *!* - // assign to this.stomach instead of this.stomach.push - this.stomach = [food]; + // assign to this.stomach for all of those prototypically Objects if not found + if (!this.stomach) this.stomach = [] // (**) + // push a new "food" to stomach array + this.stomach.push(food); */!* } };