Tuesday, July 14, 2015

This last project for the Treehouse OO Javascript course.

I was trying to write it myself but it was getting hairy, so I decided to work on it a while then look at the solution. I made an extra copy and typed the code from the video. It should work okay, right?

Nope!

I've gotten it to the point where the everything but the question displaying works. The question shows undefined and I do not know why.

I checked against the solution text, it's the same. Maybe I've looked at it too many times and I'm skipping something. I really don't know. You can answer and get a score, but the damn questions won't show!

I'm going to sleep on it and try again tomorrow. I might try to rewrite the displayQuestion method. I just don't know. But it feels awful.

Wednesday, July 8, 2015

A little coding back and forth

Treehouse added a Javascript Objects course to their Front End track so I'm in the middle of it. It seems like every few weeks the course changes, which is good but it's taking me longer to get through it.

I'm glad for this particular course because I haven't found an explanation of prototypes that sticks with me until now. The coding is getting a little harder and I had to slow the video speed down tonight to get everything typed in and walk through it in my head. I'm probably going to have to look at it again at another time just to make sure I get everything he was doing.

I clicked on a question for that section then checked my list of followed questions. One of them went to the previous Javascript Loops class, where the last project was making a searchable student database. People wanted to add a 'Search Not Found' message if the name wasn't found. I dug up my code and found that I had a note to add the same thing. Well, tonight was the night.

I read the forum solution and the guy used a flag to mark if the student existed or not. Initially set to false, it switches to true if there's information to retrieve. My code was way different from his (he used while and do while loops for everything), so I had to figure out where to use this flag without rewriting the whole thing.

First, I made sure I got how his code worked, then looked at mine. I added a flag, studentExists, to the top of the file, then I had to find where to put it. I have a print function, a getStudentInfo function, and the while loop that brings up the prompt for name. I added studentExists = true to my getStudentInfo function, to keep the not found message from appearing incorrectly.

Next I added the condition if(studentExists === false && search !== '') to my While loop. In plain English, if the flag is false and there's a name typed in, "Student Not Found" should print to the screen. I had it after my quit condition (if you type quit it quits) and the getStudentInfo call. It worked there but I wasn't sure why. How do you know the person doesn't exist if you haven't searched yet? 

So I moved the condition into the getStudentInfo function. First the search is done. If it finds something, it formats the info and prints it. If it doesn't, then the Not Found message prints to the screen instead.  This placement made more sense to me.

It didn't take as long as I thought it would, maybe 15 minutes. I thanked the guy for his solution. Then I went back to my current course and took the quiz. I probably shouldn't have done that because it could have been a long, sidetracked night, but I'm glad I did. The fact that the code is a month old and it made sense after reading through it was amazing to me.

When I worked through Codecademy there was an address book script that I was trying to add more functionality to that had a similar problem. If I had the heart to dig it up I might try to implement the same thing. It's really old. I think...it might be on Github? It might be good experience of trying to revise old code.

It was nice to be able to resolve an old issue.

Back to the night and some learning.