More JavaScript Loops & Logic

More JavaScript Loops & Logic

This week we spent some more time practicing repetition and loops. I feel like I’ve gotten the basics down on this topic, and I see so many applications for using them in my programs. We also had a test this week, and I had a good time going through it, working out several desk checks and writing a couple of programs specifically for the test. I also appreciated the opportunity to review logic and how to structure logical arguments.

Our homework assignments this week included two programs that had us practicing loops and logic. The first program case was to output the times table of 5 from 5 x 1 to 5 x 12.  To do that, I created an empty string and ran a loop that added to the string on each iteration. The string was then output to the user after the loop completed.

The second program used a loop to calculate all the powers of 2 from 20 to 231, and output the entire series of integers with a comma and space after each one, except for the last number. To avoid the comma and space after the result of 231 I used an “if” statement to test for the that result and concatenate the result without the comma and space to the existing string.

To improve user experience on these programs, I added some styling to the pages. Although this was only “window dressing,” I like my programs to have a finished look. Fellow students Shawn and Ian both complemented my use of styling.

Of the student’s programs I gave feedback on was Andrea’s Times Table. In my own program I simply used the integer 5 throughout the program. However, Andrea created a new variable and assigned 5 to it. He then used the variable throughout his program. At first I wasn’t sure what the benefit of this could be, but then I realized that with a little more effort, an input integer could be taken from the user and utilized to create a times table for any value. That input could simply be assigned to the variable Andrea had created, making this an even more useful program.

This Week’s Coding Projects

Leave a Reply

Your email address will not be published. Required fields are marked *