4th Week of #100DaysOfCode with JavaScript. What did I Learn so far?

I finally made it to a month of the #100DaysOfCode challenge!

It feels so good to finally be consistent at learning how to program in JavaScript! Its been a month and I feel like I learned so many different concepts but it also feel like I have so much longer to go (which i’m sure I do) until I can feel competent in this language. One thing I noticed is that I am learning more than I did in the past by taking time to really understand the concepts. It is no rush for me, I rather take my time and really get a grasp of these basic concepts.

Topic I learned this week: Challenging myself

Sometimes I go through concepts without really practicing what I just learned so this week I decided to do a coding challenge to test my knowledge on JavaScript objects. So the challenge looked like this: “person A and person B wants to compare their BMI (Body Mass Index)”. I did this same challenge before but just with if/else statements. So there was two things that I needed to implement in order to pass the coding challenge. The first was to create 2 objects for each person with their full name, height, and mass. The second step was to add a method to each object to calculate the BMI of each person, save the BMI to the object, and return it from the method. The last step was to log who has the highest BMI and to make sure I have a solution if they both have the same BMI.

The first step: create 2 objects for each person with their full name, height, and mass.

Creating Object for person A (Mark)
Creating Object for person B(John)

At this point I have created two objects (mark and john) and added properties (first name, last name, height, mass) to the object. This was pretty simple so far.

The second step: add a method to each object to calculate the BMI of each person, save the BMI to the object, and return it from the method.

adding method to object to calculate BMI

This is where things got tricky for me. In this instance, a method is basically just a function. This is where I learned how important the keyword ‘this’ is. So I created a method named calcBMI and then added a function inside of that method. In order to calculate mass, you have to calculate mass divided by the height squared. So knowing this formula, I basically just did simple math. What I did get wrong is that I didn't add the ‘this’ dot notation and I got an error. The next thing I did wrong was forget to return this.bmi back to the method so I was getting ‘undefined’ when I console.logged the method.

The Last Step: log who has the highest BMI and to make sure I have a solution if they both have the same BMI.

I didn't add the picture of the second object because it is basically the same but with different numbers and names.

logging who has the higher BMI

This part was pretty simple for me. All I did was add an if/else statement to log who has the higher BMI. I talked about learning the else/if statement in a previous article.

Summary

I also learned a little bit about loops but I haven’t grasp the concept of them enough to talk about them in depth so that’s on the list for next week. Overall I just been practicing what I had learned already because that’s the only way you can really understand a concept. I look forward to learning more about JavaScript.

References

JavaScript.Info

Jonas udemy Course

Follow me on social media

Instagram

Facebook

LinkedIn

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Nick Hollins

Nick Hollins

Developer. Writer. Creator. Always learning. Feel free to email me: hollinsaquile@gmail.com