Serious Functions

April 9th, 2020
javascript

Big Progress

Tomorrow, I will be wrapping up my first full week working remotely, and so far, it's been awesome. There are occasional drawbacks, like the smoke detector going off in the middle of a meeting I was having today, but for the most part, I'm twice as productive, and it's seriously nice to be able to take my breaks with my little girl. Any time I have a break, I just open up the bedroom door and go out and play with her as much as I can, or watch some cartoons with her. It's really nice. And, like I said, I'm getting twice as much done. I don't have to worry about anybody else in the office or background noises; I can just focus on my work. We are, however, trying to get a little more organized in our communication, even more so than we were in the office. For example, up until today, my cohort and I would chat on the instant messaging service or every once in a while we would meet for a video call, but we made a pact today to hold a meeting at the end of every day to go over the specifics of what we worked on and what we plan on working on in the coming days. It went really well today, and it was nice to be able to show him the progress I made today and see the progress he made on the virtual appointment setter. As I've stated several times, communication is key in any job, but even more so when you're out on your own. Now, more than ever, the lines of communication have to be clear, and with my cohort, they're crystal. The rest of the team, however, doesn't seem to be on the same level, though I don't have as much to do with them on a daily basis and it would probably serve more as a distraction than anything else.

javascript

I started off my day with an error we found in the code right at the end of the day yesterday. In several of the inputs for the amount of deeds the user holds, the amount was stuck on 0. You could increase it with the built-in arrows on the right of the input, but you couldn't backspace the 0; it was persistent. I thought this might be an easy fix, but it really wasn't. First, I changed the default value of these fields in the context to an empty string in the context, which took care of the immediate issue but caused other issues in the process. When the data goes to the backend, it's supposed to be a number, and I had just turned it into a string. So, when the next button is clicked, it now changes is back into the number 0 if the field remains blank. But, this caused another problem in the process. If they hit the back button from here or on the next page, it would be persistent at 0 again, so I had to change it back to an empty string when these buttons were clicked. I also had to do the same process on a page that is identical that you access at the end of the process. It was a mess, and I wasn't proud with the code I had written. This one is going to bother me until I can find a better way to handle this. I'm pretty sure there's an easy fix to this, but I just couldn't find it this morning. From here, I moved on to some of the changes I was told to implement in the weekly meeting yesterday to the check information step.

javascript

In the actual check image I created, they wanted the name of the plan to show up on the "pay to the order of" line, and this part was easy, apart from a little margin tweaking. Then, they also wanted to bring in the price of the plan to the box where you would write the amount of the check in. Again, this was pretty easy. Given our system of using context for managing state, it's super simple to access data like this and to get it to appear on the screen. It's just a matter of including that in the useContext call and writing it in. This was a really easy add-on, as was adding today's date to the date line. In total, between these three features, I may have spent less than a half-hour. Then came the tough part, and one I actually wasn't told to do, but thought would look really cool. I wanted to take the price and write it out as you would under the "pay to the order of" line. I learned later there is a package that does just that, but I wasn't aware of this package when I decided to create the function. I knew the price would always be 4 digits, so I split it up and created an array out of the digits. I then created several ternaries to parse the values in the most reusable way I could. The most difficult part was getting to the last 2 digits. Initially, I thought I would have to write a 100 part ternary to handle the whole thing, since I figured every value would yield a different string, but then I realized it was only 1 through 19 that would be different, and from there, it's just the 10-digit that would need to be specified to be "twenty," "thirty," "forty," etc. I could then reuse the portion of the function from the thousands or hundreds digit for 1-9 and string those out. The function was still nearly 100 lines long in total, but it could have been twice that. I think I handled it really well, actually, and it worked on the first try.

Created by Sam Thoyre, © 2019