Day 17 JavaScript Switch & Loops

Finally, the relief and enjoyment of being able to continue without having to worry about catching up with writing notes. I think that was the reason for my stress lately about learning how to code. I was being stagnant to long playing catch up with my notes. I did not like that feeling of not moving forward.

Today things felt like they were starting to pay off. The topic of today was about switches and loops. The things I’ve been learning, especially regarding math. I was finally applying and connecting with topics I was learning about.

At first, the topic about switches was a bit confusing. However when I saw the example of the code and the purpose of the function. It made more sense.

switch (new Date().getDay()) {
  case 0:
    day = “Sunday”;
  case 1:
    day = “Monday”;
  case 2:
     day = “Tuesday”;
  case 3:
    day = “Wednesday”;
  case 4:
    day = “Thursday”;
  case 5:
    day = “Friday”;
  case 6:
    day = “Saturday”;

The purpose of this example was to calculate the weekday using the weekday variable number it was given. Also visually seeing the break code function, in between each of the days helped as well. The break was a keyword that JavaScript recognizes to break out of the switch block. By leaving the switch block it is able to execute the next function. Also execute the function more efficiently and quickly by breaking as soon as it finds the value it was searching for. Without breaking the loop it would go on forever, which would not allow a program to do everything it needs to do without crashing.

I was also hyped to see that the switch was called a block since I am interested in being the blockchain industry so the word excites in this field.

With this part of JavaScript I am starting to see and feel how it is more a programming language compared to HTML and CSS. Seeing a glimpse of how statements are defined to be true or false, and also how the system searches for actions to execute. Which leads to the next action of execution which leads to the next and so on and so forth.

One thought on “Day 17 JavaScript Switch & Loops

Add yours

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Up ↑

%d bloggers like this: