Simple JavaScript Image Slideshow: Refactoring = Progress!

Now, I know the posts about me programming are a bit dull since I’m still very much a beginner, but since I didn’t have any activities scheduled this weekend and no work stuff to take care of, I felt like I was finally able to make some significant growth in my programming powers.  Admittedly, compared to anyone who is even remotely competent, I’m still a babbling baby, but still, it’s pretty cool to go back to something I made about a month ago from going along with a webmonkey post to going through and making it my own AND more easy to read, change, and follow along with.  I think the combination of those two things are something I really love about coding.  You can look up just about anything online (at least for the kinds of problems my beginner butt is running into), and then you can recreate bits of what you find with other knowledge you have to make them more simplistic or elegant.

CS vocabulary has been a bit new to me.  There are a lot of words I know in completely different contexts that have a very different definition in CS.  I’ve been trying to track new words I learn as I read about them and trying to see if I can understand them without my brain hurting while looking it up.  Sometimes I’m completely able to get it, and other times I sort of brain fart and feel like a toddler again.  So, for example, I read an article about a person who was working as a recruiter for a company.  This company was concerned about gender/racial bias interfering with its interview process, so together with the recruiter decided to do the programming portion of the interview with the candidates completely anonymously online.  Aside from written language (which one might argue could give some of this information away), he never saw or spoke with the candidates.  He gave them a refactoring challenge where they were to identify code smells.  When I read through the rest of the article, I was completely and utterly confused about exactly what it was he was having them do, but from what I could guess at the time he was having them look for hints of something being inefficient or problematic in the code then restructuring it.  Thanks to some quality time with my overlord Google, this turned out to mostly seem accurate.

Refactoring is when you alter the internal structure of the code without changing its external behavior.  When I wrote the first draft of my slideshow code I hadn’t any experience with objects or events, so when the site I followed along with pointed out different events, I just sort of rolled with it without really fully understanding what was going on beyond that when something was clicked, I told it to execute a function.  I also used global variables quite liberally, because that was the only way I really knew how to get some of the work done that I needed.  Even after I switched out all my functions to be methods instead, this hasn’t really changed too terribly much if I’m honest, but the beginning value of the variables is all easily accessible at the beginning of the method object.

Now, with the original script I had made a slight change to it.  I had added a while loop to create the imageArray[] since typing them in individual was not on my future desires list.  At the time I felt slightly successful being able to make that change, but ultimately I had mostly ended up with code very similar to the article as I wrote it after reading what needed to be done, and then I compared to what they had with functionality.  Not a great strategy, but again, the event handlers were a bit over my head at the time.

When I went through it to refactor, I renamed some variables to names that made more sense to me.  I added comments.  I restructured it to have the functions sorted as methods in objects and all the variables within objects as well.  None of what I did was really ground breaking, and a lot of it was work I honestly will probably change again as I continue learning in the next few weeks, but it helped me practice the skills I have learned and apply them, which is always helpful for retaining information and being able to use those skills creatively in the future.

You can go to my GitHub account to check out the code and the revision in a Gist.

One thing I need to revisit when I’m less sleepy is the event handlers.  I left them in HTML like I had before since I was running into strange errors when I tried placing them in the JavaScript instead.  I believe this was caused by setting the onclick handler and trying to pass it an argument, which I don’t believe is supposed to happen.  Without the argument, the rest of the code was no longer interested in functioning.  I checked some JavaScript documentation, but I wasn’t able to come up with an alternative that would work any better than just leaving the event handlers on the HTML page.  I will likely need to review options when I’m less sleepy, and with any luck, I’ll keep thinking about it while I dream and wake up with an answer!  I love code dreams.  So productive.

Next: to improve the Battleship game.

Advertisements
Simple JavaScript Image Slideshow: Refactoring = Progress!

I Earned A Badge For Walking! (OR it turns out gamification DOES work on me and Fitbit made me walk in the rain OR benefits of interviewing)

So as I’m sure anyone who reads on a regular basis is aware, I’ve often complained about the fact gamification doesn’t work on me.  For those lucky enough to be out of the know, gamification is the habit of sites to give you badges, points, and other silly, meaningless measures of artificial success for meeting mild milestones.  Think of it as participation trophies on steroids and then delivered with high enough frequency that anyone with a gambling addition would be lost in the abyss.  It’s employed by Treehouse, Khan Academy (for anyone who works with kiddos or IS a kiddo), Codecademy, and was popular on a number other sites as well.  In the academic arena, I was never really motivated by them because typically my drive to learn surpassed that.  So when Treehouse used to send me daily goals, I had already blown them out of the water by doing 10xs as much as what was asked of me.

This wasn’t quite the case with exercise sites.  Now, I exercise a lot typically.  In the summer, I’m outdoor constantly swimming, paddleboarding, running, hiking, and doing yard work at my parents’ house.  Before my shoulder got busted, I used to spend my winters rock climbing indoors since I’m a coward who is super anti-injury.  After my shoulder got busted, however, I’d been experiencing a few issues.  1) I was told to not go rock climbing (boo!) even if it was indoors for obvious reasons.  2) I still didn’t want to go outside in the rain.

I set a goal about a week before I had my interview with Ada Developers Academy to go exercise outside even if it was rainy in the form of walks since the indoor gym and treadmill made me not want to move anymore.  That same week, however, the weather was absolutely gorgeous, so I had no problem meeting my goal. During the interview, one of the questions was about what was something you felt you should be doing or were already doing and wanted to continue doing, and how you would plan to do so.  I felt a lot of the questions were aimed at asking if I was responsible repeatedly and trying to clarify, just in case, am I responsible?  I am!  I really, and truly am!  Even if I did unintentionally insinuated that all East coasters are blunt/rude – but that was just an example of 17-year-old me being super unfamiliar with someone saying anything playfully derogatory that wasn’t sarcasm!  27-year-old me is totally cool with that, married an Easter, and has a best friend who is pretty oblivious to sarcasm.

My “continue doing” example was to learn programming, which I have been doing.  I’m automatically reinforced for studying it, because I absolutely love it, so it’s not particularly challenging for me to continue doing.  It’s like telling me to eat dinner.  No arguments from me there!  My “should be doing” example was of going outside to exercise even in the winter.  I know I should be doing it, and when weather permits, I love it, but even when it’s a bit gross outside I need to get my mercurial butt outside and embrace the drizzle.  My plan was to put it on my calendar (done), and then obey my calendar (always do).  While I could get myself out for 30 minute walks during lunch, I still struggled to motivate myself to do much beyond that, though I’m sure if I put it on my calendar to do more I would.  It’d probably help if I got waterproof shoes that aren’t winter hiking boots.

But you know what’s better than waterproof shoes?  Electronics!  The best kind of technology.  My friend had a Fitbit that wasn’t tracking her stairs properly, and when she was sent a new one they told her to dispose of the old at the “nearest electronics recycling center”.  That would be me!

Now, gamification for other exercise sites has never really worked for me.  Here’s why: it wasn’t attached to my wrist.  A Fitbit for me is essentially an adult version of the tomogatchi pets I had as a kid because my mom told me that two dogs, lizards, 2 hermit crabs, 4 birds, and a koi pond with a fish unfortunately named Jelly Boy (he was squishy!) was enough pets, especially after the bull frogs ate our entire goldfish pond.  It satisfies all my same button pressing, staring at progress urges, with the added bonus that there’s no fake poo to clean up or the risk of fake pets dying by the use of the fitbit (that I’m aware of).  So competing with my friend, earning badges, it’s all amazing.  And I can track my sleep patterns! Mind?  Blown. Did I mention I also have access to a bunch of graphs with all this data that I can export into an excel or csv file?  All my geeky data collection urges are satisfied too.

In conclusion, I can no longer convince myself I’m above addictive psychology tricks like gamification, but I already knew I could succumb to them based on Steam Summer Sales alone.  Despite not having waterproof shoes, I walked 4.5 miles today, over 10,000 steps, and multiple flights of stairs.  All because when I checked my phone it told me I hadn’t completed those things successfully yet, and glancing at the time on my Fitbit when I walked to the restroom confirmed this as well.  If all those websites trying to get me to exercise years ago were connected to my wrist, I would have been in such better shape. Now to track my sleeping for another night and wonder if there’s a correlation between “restless sleep”, and the fact I read books about coding before bed.  Me thinks perhaps.

I Earned A Badge For Walking! (OR it turns out gamification DOES work on me and Fitbit made me walk in the rain OR benefits of interviewing)

You Sank My Battleship! (Learning JavaScript Continued)

So I’ve been learning JavaScript using Head First’s book, as I’ve mentioned about 12 times when frustrated with the pacing of other sources.  Around the 8th chapter, you’re given the goal of developing a JavaScript web app for battleship.  They go through it step by step how to make it, but typically when given a project, I’ll read the next step and create it on my own.  I still don’t feel I have a great conceptualization of how those steps are reached – I’m working on it – but this is a good start.  Afterward, I tested, and then I’d compare my code to the book’s.  Obviously, I learned through the book, so in some areas what I produced as incredibly similar to what the book suggested, and sometimes what I did was less efficient, and others I believed it was more efficient.  As far as event handlers, though, I had to look up information on that mostly and definitely need to learn more before going further.

Battleship Link!

My next steps for it are to include a way for the player to place ships for the computer to guess in order to compete and add sound.  I think this will help with my issue with feeling a lack of experience going from start to finish with a project.  Also, my goal is to change what I have to make it response as well, since currently on my phone, while I can zoom in and play, I feel like I should play anywhere!

The game itself isn’t very fun since it’s like playing Battleship with a wall, but I still think it’s a pretty good project for learning.  Plus, it’s just nice to look lovingly at something you made and feel all productive about it.

What I’ve learned so far with this project: testing after each implementation of a code block is essential.  Objects make me feel warm and fuzzy, and it’s lovely to be able to make information more easily structured using them, and I haven’t really used them until now.

That’s all the post for today, folks.  Back to work I go!  Happy Digital Learning Day!  Practice safe computing!

You Sank My Battleship! (Learning JavaScript Continued)

Change: IT’S COMING FOR YOU! (AKA puberty, husbands, and JavaScript)

I’m going to make a bold statement that you should just accept as fact: I handle massive change quite well.  Now, hear me out, I legitimately handle it really well.  For you naysayers, what I don’t handle well is the uncertainty of knowing whether or not massive change will happen.  (As a warning, the next few paragraphs go into moderate detail about my realization that puberty was a thing and a thing I would be experiencing eventually.  Please feel free to skip this if your stomach isn’t up for armpit hair.  I won’t judge you.  Actually, I won’t even know about it, which is even better!  Thank you anonymity of the internet which I’ve violated by using my real name on my blog and linking to it from my personal website.)

For example, when I was in 3rd grade and I had the misfortune of being exposed to my first sex ed video about your body changing in strange and mysterious ways thanks to being in a multi-age classroom where no one else in the building was exposed to it until 5th grade.  I was distraught.  Fat balls bouncing around on my chest until the end of time that would inflate and shrink based on weight, age, and baby-making status?  That sounded horrible.  And why more hair?  I kept seeing all these razor commercials, and so I was pretty sure growing more hair was really just a ploy to make them more money and there had to be a way to stop it.  My armpits were completely comfortable without anything stinky coming out of them, and no, I don’t want to rub something inside them every day to keep from offending other people’s nostrils, but thank you for the soap.

The kicker?  I was going to bleed for about a week once a month until sometime in my 50s or 60s?  Why?  No, seriously, why?  That seemed more like a ploy to slowly kill me than an inevitable fact, and I immediately complained to my teacher about these potential changes.  She told me it was something all young women go through, it was miraculous, so on and so forth, to which I was horrified.  I needed to know when.  If I knew when these horrendous things would happen to my body, warping it into a grotesque vessel for this torment supposedly known as “womanhood” topped off with this thing called cramps that until then I had only heard of as a reason to not go swimming after eating (false, by the way), then I knew I could prepare for it.

I took the only reasonable action.  I demanded my teacher tell me exactly when this horror would be unleashed upon my body, to which she responded, “Everyone has it happen eventually, it’s just whenever is the right time for you, dear!”  Dear?!  Ms. C, I was going to bleed most of my life and experience something that kills you when you go swimming with hair all over the place and strange, awful smells dripping off my body, and I was now “dear”?  Absolutely not.  Completely inaccurate!

I immediately set to waiting, uncertain when to prepare for the change, but knowing it would come.  I prematurely started doing things my older sisters were doing, knowing it would inevitably be my fate.  I shaved my nearly hairless legs and armpits.  I wore a sports bra.  I waited with the madness once encompassed by Waiting for Godot, and this was in the days before smart phones, so waiting didn’t involve reading the internet for entertainment either.  It was silent patience embodied by pre-adolescent madness.  I had encountered limbo.  Waiting for Armpit Hair.

That’s the kind of change I don’t handle the best – the kind that is maybe going to happen but hasn’t happened yet and you have no real way of knowing when so sort of make plans for it but also sort of don’t because you need to continue existing as you are now or else you’ll be a useless lump of lady meat.  So I’ve made an effort to address that, since after all the root source of my issues with the unknown is anxiety about when it will be unleashed upon me, which is simply silly.  After all, the most miraculous thing about life is that it happens while you’re making plans, and most iterations of those plans become wasted.  Fortunately, being the nerd that I am, I create multiple iterations of most plans, so while the vast majority are wasted, there’s always one lucky guy that gets to be executed, and he prances forth before all my wasted energy that’s discarded to the side as irrelevant, bragging and boasting about his momentary utilitarianism.

Now, for you naysayers, let me give you some examples of change I handled quite well.  I, a former commitment-phobic lady who hadn’t really dated anyone for more than 3 dates aside from one abnormal instance prior that was still within a month’s span, very easily accepted when I met my husband I would be an idiot not to spend the rest of my life with him, so married his handsome self.  Once I realized I was going to most likely marry him, the when of it all caused some stress, but thanks to constant exposure to that uncertainty (including my husband moving up the wedding date so we had 3 weeks to throw it together in the middle of the school year, which was amazing though very tiring), I got over it, which has been pretty helpful for rolling along with a fairly impulsive man.

I transitioned into an independent adult pretty well too.  Talking to a lot of my friends in undergrad and some recent graduates at the time, a number of people apparently had absolutely no money sense when they were first independent, and though credit cards were free money.  I, fortunately, never had that mindset, so I never built a substantial amount of debt I’d need to claw my way out of.  There’s definitely some weird stuff about being an independent adult, such as retirement and insurance, but researching it hasn’t been too rough, and I feel I’ve generally made fairly good decisions in those areas.  I’m pretty grateful to my mom for my money sense, since when I was a teenager I thought it was weird she talked to me about money, but I was later grateful she did.  There were some lessons that I’d rather hear from her than learn elsewhere, including the infamous, “Your father wants to buy a tractor and we live on a 3000 sqft lot”.

Finally, the decision to program.  I won’t go into too much detail about what prompted the decision, but I have set solidly that this is what I want to do.  Programming and I have been 10 steps apart most of my life as I have previously mentioned, and now that I’ve accepted the fact that I love it, I feel like kicking myself for not jumping in head first sooner.  This isn’t to say I have any regrets about decisions I’ve made in the past as far as my education and career go, and I certainly think every experience I’ve had has helped shape who I am today.  I’ve learned so much patience, empathy, compassion, working with little resources, and how to positively influence someone’s life to help them make more proactive and productive decisions.  There are leadership skills you learn in teaching that if you can apply in other areas of your life lead to a great deal of positive change for those around you in general.  I know how to have tough conversations with people about anything from substance abuse, body odor, or the injury their decisions are causing their relationships with others and themselves.  I know how to tell someone they’re wrong, but do so in a way that they know I still care about them, and that their wrongness doesn’t impact their goodness.  Teaching has genuinely made me a better human being.

Coding takes a lot of aspects that I love about teaching but applies them in a very different way.  To name a few, you constantly learn new information to better implement practices (though for me currently this may be extremely more so since I’m such a novice).  You also get to solve problems and puzzles, which I absolutely love.  It’s great tackling a puzzle without clearly knowing the solution then reaching that, “Aha!” moment later.  Then there’s the collaboration.  Talking to someone else about code and reading their code helps solidify my understanding of concepts, just like watching someone else interact with a student with challenging behavior in the classroom to learn their approach.  I also love that once you learn something new that can make your code more elegant or efficient, being able to go back and revise it, test it immediately, and see the results.  Testing it and trying to break it is great, since it’s like finding holes in your logic constantly then attempting to improve it.

Alright, new goal, make less posts where I inevitably start talking about how much I like coding and learning.

I’m currently learning JavaScript, and after jumping through many sources of information trying to find what works well for me, I have set on Head First’s JavaScript book.  I’m really enjoying it.  I’m on day 3 using it, and already I’ve covered more and more in depth than through months of using other modules to learn.  Part of why it’s working for me is the fact you can quickly read sections you’ve got down, but also because of how many different ways it shows different vocabulary and concepts.  Retaining it all is so much easier than having someone pass over a term briefly but never revisit it.  I really wish they had a recent book on Python too.

My current project is a game of Battleship.  I’m not too far on at at the moment, mostly working on data structures, but I’m pretty excited to get it all working.  In fact, I better hit the books and keep learning so I can get it down.

On shoulder related news, I had a doctor’s visit today.  I’m on the same restrictions for 6 more weeks, but he gave me a steroid injection in my joint, and I have got to tell you, so much less pain afterward.  It was amazing.  The reason for it is so we can push it in PT a bit harder since currently he believes pain is inhibiting my progress.  More pushing is amazing news.  I feel like it has been forever at this point, likely because it has been, but I’m truly grateful for the progress I’ve made.  Each day I feel like I’m getting a bit more of my strength back, and each day the pain decreases a bit more.

Change: IT’S COMING FOR YOU! (AKA puberty, husbands, and JavaScript)

MOOCs (Treehouse, Udacity, Udemy, Codecademy, etc): A source of slooooow frustration to learn coding. Long live books!

I’ve recently learned after another week of blog neglect that I had a visitor from Canada, Jamaica, and Germany.  Welcome, non-Americans!  Hello to all the American readers as well.  My faithful 15 who see this show up in their news feed then click away in hopes of something more interesting.  You’re appreciated.  Adored even.  Adored so much that I drew an MS paint picture of all of you to show my adoration!

followers

Sorry for the pile of you stacked together.  I ran out of room for standing people, and then my hand got tired.  I did, however, include that one guy’s two kids.  Yeah, you know who you are, that one guy, and thanks to personal information you divulged on the internet I know you have children.  Don’t worry, you know about my little dog too, so we’re pretty even on the creepy factor.

If you’re the person who is singing, smiling, or permanently in a chair refusing to move while everyone else is standing, you’re awesome.  You’re not like the other followers who just pile up on the floor when the room gets crowded or awkwardly stand on other people’s heads.  You know what’s up.

Alright, odd monologue about nothing aside, let’s get back to the point, shall we?

I previously wrote a post about where to learn web coding where I compared Udacity, Udemy, and Codecademy as either very cheap or free learning methods.  I ultimately decided Udacity was for me, then had to go back and redact the monkeys out of that statement when I realized Udacity was for me situationally but progressively got less for me and more for no one as they stopped describing the “why” and got into just straight up “how”, which put me back to inferring the why a lot, which I’m fully capable of doing, but for very basic things was just so inefficient and rather than watching video lectures I could get my Google search on much faster (which is to say still rather slowly in comparison to having a skilled teacher instruct me).  I then thought, hmm, well, I keep getting spammed by CodeSchool and Treehouse ads on youtube, why not succumb to my Google overlords?

I went with Treehouse because my husband kept telling me how great it was, and I’m super easily influenced by incredibly handsome men who are easily excitable.  Plus, upon researching it, everyone seemed to support it for beginners and CodeSchool was more for intermediate people.  After Codecademy and some Udacity, I didn’t feel very intermediate.  So I signed up, and after the first course on “how to make a website”, I was grateful how much faster I gained the information compared to Udacity and how complete it was.  I happily petered over to my website and put some fancy looking things on it that changed size and disappeared as the screen resolution shrunk.  Then I did the next part, which was “CSS basics”.  Which was hours of the same information.  I was not pleased!  But I figured I grew in depth slightly, so maybe it was worthwhile.  Or so I tried to convince myself.

Then I got to JavaScript basics.  Also, no bad.  It was a bit slow, very a bit slow, and I was introduced to a concept and would start completing the programs they were going to use as an example before the example happened.  I figured it was good practice, so why not carry on?  Then…then I got to HTML forms.  I heard the advice to practice with CSS on your own since how you format an HTML form behaves in strange ways compared to usual HTML and that we couldn’t actually do anything with the form without a server side language either.  This made me want to bang my head on the wall.  I mean, what’s the point in wasting the time to say that if you aren’t going to go over why it behaves strange in comparison and what some of that behavior looks like?  But again, I used my inferential skills, and all was well.  The second part was incredibly frustrating, though.  I’ve been trying to apply whatever I learn as soon as I learn it so I can retain it, however having just learned a skill I couldn’t do more with than make a form that went to nowhere wasn’t particularly useful for practicing.  Motivating myself to get through that section involved a lot of tooth pulling.

I’ve moved on to more JavaScript, but it still feels like it’s moving slow.  I’ve invested over 25 hours into this program so far based on their in program timer for how long it should take to complete (and I’m not sure how much their track changes have adjusted this), but I feel like my retention is pretty poor.  Since doing my photo gallery slide show side project and learning far more from that, I had continued doing Treehouse, but I realized my issue with it.

Treehouse is intended for everyone starting at next to no computer experience, which is made pretty clear from their first course in the Front End Web Developer track.  Massively Open Online Courses are like general education in public school.  It’s meant to serve everybody and assumes everyone knows nothing, even though that’s not necessarily the case.  This isn’t a bad thing, it’s just if you can infer, and if you need some redundancy for retention but the redundancy you respond to isn’t someone telling you the same thing repeatedly, then it’s probably not a great resource for you.  This is unfortunate since I respond really well to hearing information then discussing it with others, and MOOCs provide auditory input.  Consequently, I think a bootcamp such as ADA would be a good match for my learning style, but whether or not I will be able to participate is undetermined yet (since, uh, applicants hear back around mid-March for interviews and end of March for actual acceptance?).  Whether or not ADA is in my future, I still want to learn, so I’ve moved on to another resource.

A book!  I know, I know, learning from books is a super novel idea that no one until this very moment has thought of.  My husband had used the Head First C# book, but he eventually found one part too hard and gave up.  I was never particularly interested in C#, so I never checked it out, but I checked out a couple of their other books while loitering in book stores and then checking the kindle sample version.  The strategies employed are simply good teaching (and entertaining!), and on top of that when I looked at the Java book, the first chapter nearly caught me up with everything I’d learned in roughly 10 hours+ on Treehouse.  So…yeah, I went with this book for the time being.  It’s super interesting to read and engaging, which helps with some of the motivational deficits I’ve experienced with watching MOOC videos.  They had an older Javascript book that was apparently pretty not great, but the internet tells me this is a good resource.  Then again, the internet also told me that Udacity, Treehouse, Udemy, and Codecademy were good resources, which to a point they were, but had a lot of room to grow.

I haven’t decided if I’ll keep dabbling on Treehouse for a bit or not.  After multiple lessons that I couldn’t put into practice, the slow pacing, and the seemingly limited breadth, I may have outgrown it.  The biggest reason for people to go to MOOCs instead of scouring the internet is because they want to save the time spent identifying resources to learn, what to learn, and sometimes the more personable approach to learning with a video lecturer.  A lot of MOOCs still seem to structure their content illogically (ex. HTML forms without any back-end knowledge to make it actually work placed in the middle of JavaScript lessons when no JavaScript is actually needed in order to use HTML forms), which is a good area to improve, and some focus more on having their students regurgitate information than practicing to mastery.  Udacity’s end of unit assignments, practice problems, and optional homework were great for independent practice, but often the quality of teaching dipped.  Treehouse also started having some independent practice exercises as I progressed, but the slow pacing caused me to treat everything like an independent practice exercise, which left me with a new content deficit.  Determining sequential, engaging curriculum is an area any education needs to firmly establish to help educate its students, let alone retain them.  Pacing, however, is usually more an indicator of who you’re trying to teach.

Hopefully my books + Google strategy will go well.  Otherwise CodeSchool has nearly all of the MEAN stack taught on their site, and that might be an appealing alternative.  So far, though, I’m a big fan of the book strategy.  …Don’t read near the end of my last blog post discussing coding resources where I said the same thing then shortly after changed my mind.

MOOCs (Treehouse, Udacity, Udemy, Codecademy, etc): A source of slooooow frustration to learn coding. Long live books!