Problem Solving

The Problem

One of the problems I had this week was in assigning a child object to a parent object:

        Parent object:
        
        var terah = {
          name: "Terah",
          age: 32,
          height: 66,
          weight: 130,
          hairColor: "brown",
          }
        
        Child object:
        
          const ben = {
            name:”ben”
          }
        
        
      
The above is what I had so when I did terah.children = ben. It didnt work. I did some console logging so I could see what the terah object looked like and the ben object was. I reread the question which was “ben should be defined as an object and assigned as a child of Terah” and then “Terah's children should include an object called ben which has a name property equal to ‘Ben’." After talking to my cat about this and doing some googling on adding objects to other objects i came to my answer of terah.children.ben = {name:"Ben"} which did work meaning i didnt need the child object i had.The outcome of the parent object looking like this:
      Parent object:
      
        name: 'Terah',
        age: 32,
        height: 66,
        weight: 125,
        hairColor: 'brown',
        children: {
          ben: { name: 'Ben' }
        }
      
      

Reflection of solved problem

Looking back at this i can see that i used at least two of the techniques(google and rubber ducky method) in the below section. it was also nice to learn that you can just add propterties to objects in this way rather than having to define a seperate object before adding it to the new object.

Techniques

Pseudocode - This is super helpful to write the steps of an algorithm in English plain .
Example for getMail():

        Walk to end of driveway
        Open the mailbox flap
          FOR every letter in mail box
            Take letter out
          ENDFOR
        Close mailbox flap
        Walk back up driveway
      

Trying something - if you are unsure where to start. just try something. anywhere can be a good starting point. you might start with a For loop but end up with a simple switch statment

Rubber ducky method - The rubber ducky method is another step in problem solving. This involves explaining the problem to a object. I like to talk to my cat about what Ive done and what the problem could be. Sometimes just talking out-loud helps find the issue.
rubber ducky

Reading error messages - Reading errors messages if you get one, is helpful as these usually tell you where the problem is in your code .
TypeError: Cannot read property 'name' of undefined at Object.athleteArray..win (/home/runner/JS-Olympics/index.js:39:31)
this tells us that the error is in index.js on line 39

Console.logging - console logging can give us a good picture of what different outcomes are giving. this is most used in debugging

console.log(athleteArray)

Googling - The next step if you are still stuck should be to google the problem to see if there are others out there that have had the same issue. A lot of answers can be found on stack overflow.

Asking your peers for help - If googling the problem doesn't help then asking someone else can be helpful. This brings a fresh pair of eyes and knowledge to the issue

Asking coaches for help - This should be the same as above but after you have asked your peers for help and are still stuck. The extra knowledge and experience they have should hopefully help.

Improving your process with reflection - with reflection of code you might find a new way of doing a certain part of code or maybe even find you can skip a part cause the code no longer needs it.