Showing posts with label Javascript. Show all posts
Showing posts with label Javascript. Show all posts

Tuesday, August 6, 2019

Day 121: Javascript Calculator Project Completed!

The Javascript Calculator project with keyboard support was not as terrible in terms of bug squashing (and general frustration) as the Etch-A-Sketch Project.


Two points of interested of this project was that:

  1. When I began, I started going down this weird rabbit hole of pushing the clicked numbers into an array and then joining them for calculations. There were other funky stuff I was trying as well that I don't quite remember. It was a not insignificant (to me) amount of code written up that I ultimately ended up tossing out the whole thing and starting all over. 
  2. One of the extra credit assignments in the Odin Project is to include keyboard support. I wrote up that bit pretty quickly and it worked for the most part, but had weird bugs that included other characters that was strangely (to me) not being filtered out by the conditional. I had used "keyup" as the eventlistener and tried a few things to fix that bug. Eventually, I decided to try using "keydown" instead. Literally just switching out one word, "keyup" to "keydown" worked! I still don't quite understand why and will need to read up on the differences between the two. 
Overall, it was a really enjoyable project! FreeCodeCamp also has this project as part of their front end libraries certification, which I was planning to just submit both to TOP and FFC in one go. However, I decided to hold off on submitting to FCC since this calculator was written entirely in JS. I am still taking my time going through the React and Redux sections and eventually would like to refactor the code to use those libraries in the future since the whole point of the project for the FCC certification is to get more experience with them. 

The next project I will be working on is the Pomodoro Clock project which again is an assignment in both TOP and FCC. I will be taking the same steps, working with it in vanilla JS and then later refactoring to React/Redux. 



Wednesday, July 31, 2019

Day 115: Etch-a-Sketch Project

So I finished my etch-a-sketch project for the Odin Project a few days ago. I meant to blog about this sooner but needed a few days away from it for a bit. More on this later...

I'm happy with how it turned out!
It was a bumpy ride though... 

The requirements for the project are the following:
  • Generate a grid and allow users to choose the number of cells in the grid while conforming to the original grid size.
  • Allow users to clear the grid so they can draw something new. 
  • When the user hovers over the grid, allows them to change the colors of the cells. 
  • Optional: Allow users the option to select a random mode where each pass through a cell changes to a random RGB valu.
  • Optional: Allow users the option to select a shader mode where each pass through a cell adds another 10% of black to it so that after 10 passes is the square completely black.
  • My Extra: Allow users to have an eraser tool
  • My Extra: Allow users the option to pick their own color using a color picker.  
I pretty much got it working in a single coding session and was so gosh darned pleased with myself. "Yeah! I know how to do stuff!"

But it wasn't quite working as intended.

When you clicked the shader button, it worked as it should, but the bug was that it became persistent and continued the shader functionality (decreasing in opacity) when you switched to any other mode as well. Clearing the grid or resizing it did not help. Nothing short of ctrl+r made it go away.

Not working as intended at all!

So I spent the next THREE days trying to figure this damn thing out. I almost got it working close to intended when I switched from using opacity to straight up changing the color values themselves (i.e. hex value of #999999 => #111111). However! There were other bugs related to the shader, where when you clicked the shader (it worked), but when you clicked it again it still worked, but now instead of going through 10 passes to get to black, it was 5 passes. If clicked shader again, it was now just 2 passes to get to black. Then 1. Other bits and bobs I tried was using the removeEventListener, forcing refresh (no, no, no), and tons of refactoring.

So with my frustrated grouchy face at home, cue the husband noticing and asking to look at my code. I grumpily told him what was wrong and after a ton of console logs, we figured it out.

I was calling the mouseover eventlistener inside a function. This function was later called from the click eventlistener.

const drawShade = () => {
  sketchPad.addEventListener("mouseover", e => {
    e.target.style.backgroundColor = "black";
    let opacity = Number(e.target.style.opacity);
    if (e.target.style.opacity <= 1) {
      opacity += 0.1;
      e.target.style.opacity = opacity.toFixed(1);
    }
  });
};

const shade = document.querySelector("#shade");
shade.addEventListener("click", e => drawShade());

Yeah, you're not supposed to do that! Why? Because once you call that function, it's going to have that mouseover eventListener hanging around forever (until refresh). And when you call the function again by clicking on the button again, that evenListener is going to duplicate itself! And so on and so forth.

So this is just another case of my wanting to cram in as many things at once instead of focusing on one functionality at a time.

For something like mouseover that is persistent, that function should only be called once. And you have to work around creating something that manages the various modes.

In the end, I created an actual "mode" value that defines what the mode should be based on the user click. And the drawMode() function, being called only once and is persistent changes the mode based on the user click.

Here's the old code when I thought I was nearly done. Compare that sucker to how different it is from the final code. There was a lot of refactoring done!

Touchy Feely Stuff

Oh boy, was this project a roller coaster ride. Before I started, I was super nervous. You know the whole thing about "if I try, I might fail. If I don't try at all, I can't fail... right?" Yeah, that's why I am always nervous before starting any project. The fear of failure.

But I started it (after procrastinating a bit), I got the grid creator to work within minutes using CSS grid, fixed up the CSS to look the way I want it to (I am really pleased with it!). I got most of the functionality to work with ease and pretty minimal googling. Huzzah! I was on cloud 9.

Then that bug reared it's ugly head. Like I said, I suffered through it for 3 days. For comparison, the project took a total of 17 hours... 10 of which was bug fixing. Yeah... And this was the time where I'm thinking "This is the second, the SECOND project on the Odin Project. If I can't do this right, how the heck do I expect to do the rest of the projects which are harder!?"  SO. DAMN. FRUSTRATING.

When I understood why it was bugging out and fixed it... it was like those 3 days were erased. Total euphoria and relief. And exhaustion. Hence why I had to take a few days away from it to decompress and let it sink in a bit.

But this is how you learn and become a better developer right? Through hours and hours of frustration and when its solved, you feel like a million bucks. I am OK with that.


Friday, July 19, 2019

Day 103: First Pull Request!

It's not much but I just made my first pull request to something that is not myself and it was accepted! Huzzah!

I am so stupid excited right now. 

It's not much. It is literally just updating an .md file as a part of the Odin Project curriculum when you complete your projects to include a link to it, but it's still sooooooo exciting to see everything in action and be included!

That said, I did finish my rock, paper, scissors project last night. Give it a whirl, there's a treat if you win! (or lose). It took about 7 hours to do spread between 3 days. I wanted to do a bit more than the minimum viable product, so I spent more time on it than was necessary. The time count actually includes looking up images and sounds for it so it was not all super productive coding, but time well spent that was still important to the project. It was nice to brush up on on a tiny bit of CSS with the project as well.

The next project, doing an etch-a-sketch seems a bit more complicating, but it should be interesting! I always like to quickly peek at code from other folks... and most of them are less than 100 lines of JS. Crazy how something may seem so complicated, but can be done in much fewer lines than I always think it would be.


Saturday, July 13, 2019

Day 097: The freeCodeCamp JavaScript Algorithms and Data Structures Certificate!

Look mom! I got the thing!

This was after completing their last problem: JavaScript Algorithms and Data Structures Projects: Cash Register.

Mom, it was a harrowing ordeal to get this thing!

As you know, I track my time coding or learning to code with Toggl. How much time did I spend on this the last problem?  In total about 9 hours and 52 minutes. 

Holy mother... why?

The long and short of it is that you need to know the value of each of the currency item in order to solve the problem. I had set my penny to $0.1 instead of $0.01. 

I basically solved this damn thing like 3 different ways after working with that incorrect original reference data the whole time, but could not get why the heck it was not solving. Part of the reason was because I was adamant on getting it done on July 12th so I kept cranking at the problem up until around 3am in the evening until I finally gave up for the day due to sheer exhaustion. 

So roughly 9.5 hours was spent banging my head on this thing. In the end, I asked my husband for help and after a series of questions of why... that we identified that my penny was off by a decimal in like 10 mins. FML

And after that, the problem was solved as a whole pretty quickly after writing out the last bit of logic for the insufficient funds cases. 

I should have given it a rest and/or asked for help much sooner. The bulk of the solution was written out and validated in about 2-3 hours and it would have been solved by then if it wasn't for being off by the decimal. I kept hammering at why it was not working with a tired brain which worked against me. And my stubbornness (which is amplified with the tired territory) pretty much made me avoid asking for help until I became desperate. I really need to stop doing that and be better about knowing when to stop and knowing when to ask for help!

So the takeaway from working through all these algorithms is not the content itself (though I did learn lots!) but mostly about myself in how to be a better person and a better programmer.

Now that this is done and over with, I still want to solve the remainder of the Intermediate Algos that I skipped, but I want take a break from algos problems in general for a few days so I can move on to the Front End Libraries section in FCC, the more fun and creative bits.

I am pretty pleased that I manged to get the second certificate before my 100 days on Tuesday!


Wednesday, July 10, 2019

Day 094: FCC Intermediate Algorithms: Wherefore art thou

Currently, I am only about halfway through the FCC Intermediate Algos section. I had initially skipped Intermediate Algorithm Scripting: Wherefore art thou since it is dealing with objects and objects are not my cup of tea, but then I encountered another problem with objects so might as well get this one done before moving on, yes?

I really like working with challenges that have arrays. I understand it and enjoy it. But when you throw an object into the mix, I start having problems. And then you add objects into arrays or arrays into objects and nest them in some way or another, my eyes get crossed!

It is partially because the object references the location and not really the values itself (or something like that). So when you compare the following "same" objects in the below array, the result is a false. Try to iterate through that mess and you can get a sense as to why it confuses the heck out of me.

const testArr = [
  { key1: "value1", key2: "value2" },
  { key1: "value1", key2: "value2" }
];

console.log(testArr[0] === testArr[1]); // false

But objects is in part what makes Javascript OOP, so I better get used to it.

The FCC challenge requires the following:
Make a function that looks through an array of objects (first argument named "collections") and returns an array of all objects that have matching name and value pairs (second argument named "source"). Each name and value pair of the source object has to be present in the object from the collection if it is to be included in the returned array.
whatIsInAName(
  [
    { first: "Romeo", last: "Montague" }, 
    { first: "Mercutio", last: null }, 
    { first: "Tybalt", last: "Capulet" }
  ], 
  { last: "Capulet" }
);

// should return [{ first: "Tybalt", last: "Capulet" }].

Being aware of the conditions of objects and key value pairs that make it hard for me, how did I initially tackle the problem? I used Object.keys() and Object.values() to convert the array of objects into an array of arrays, combining the keys and the values as "keys+Values" with use of the for.. in loop, something like the below as an example.

const srcKey = Object.keys(source);

  for ( let i = 0 ; i < collection.length ; i++){
    for (let key in collection[i]) {
      console.log(key + ":" + collection[i][key]);
    }
  }

Midway through writing up my answer, I realized that it was probably a very inefficient and um... bad way to work with objects in getting to the solution.

So I peeked at the hints.

I was on the right path to use the Object.keys(), but I wasn't using it correctly. And filter() and Object.hasOwnProperty() also made an appearance.

I didn't quite consider using filter() because it is a method on an array, not object. Since they are objects, I kind of agonized over that and overlooked the fact that it was an array of objects. So filter will work fine in this case. It almost always does with these matching type problems.

In my own words, filter() accepts a condition and returns that which is true or "passes the test implemented by the provided function" (per MDN). You plop in a true or false function and it gives you an array of whatever values are true to the condition.

Okay, it sounds like I have to write function that checks whether any part of the source matches the submitted collections array by looping through the array (of objects). And somewhere along the way, hasOwnProperty comes into play in there. I'm not sure if I ever used hasOwnProperty and how that comes to play. So what does it do?
The hasOwnProperty() method returns a boolean indicating whether the object has the specified property as its own property (as opposed to inheriting it). --MDN
I am going to need to use it to check if the objects in the collection has the properties of the source. Fair enough.

So cue the many searches and hours spent on this problem and I finally gave up and took a look at their code solution.

I came close to their basic solution. Most of the bits and bobs were in the right place, but I could not get the condition statement right. /sigh Always foiled by that ! operator. Here's my completed solution after reviewing theirs:

function whatIsInAName(collection, source) {
  const sourceKey = Object.keys(source);

  function existsInArray(obj) {
    for (var i = 0; i < sourceKey.length; i++) {
      if (obj[sourceKey[i]] !== source[sourceKey[i]]) {
        return false;
      }
    }
    return true;
  }
  return collection.filter(existsInArray);
}

Why does this work? Let's deconstruct this a bit using the first test case.

Step 1. We need to use Object.keys() which will return the object's name for the key value pairs. We need this information because our task is to find the one that matches with the source. In this case, we need to match the last names (key and value).

Step 2. To simplify matters a bit, I created the "sourceKey" which is the "Object.keys(source)" to keep the code a bit cleaner. You can indeed use something like "Object.keys(source)[i]" later in the conditional part of your code, but it gets harder to read. At least for me this is the case. This code produces the following:

console.log(Object.keys(source)) 
// returns "last"

Step 3. In peeking at the hints, I found that filter() needed to be used. So in this case, it is a matter of filtering out the objects in the array that does have the same sourceKey and sourceKey value and returning the objects that match in its entirety, even the parts such as the first names and values that do not match.

I am still wrapping my head around filter(), reduce() and the like, so I rely very heavily on the documentation and the examples therein to continue. I found the Filtering invalid entries from JSON example to be particularly helpful. So I create a function to check if the source key, i.e. the last name exists in the provided collection.

Step 4. I create the "existsInArray()" function that essentially takes in an array of objects as the parameter (which is the collection) which will be run later when used in conjunction with filter(). I'm, largely following the example in MDN where were will need to call the following eventually:

return collection.filter(existsInArray)

This is the same as checking through the below:

console.log(collection[i][sourceKey[j]]); 
// is same as
console.log(collection[i].last)
// returns all the last names

It is similar to collection[i] because remember that it is built in that filter() will iterate through the arrays so there won't be an actual need to iterate through the array. Though of course it is still possible to solve this problem without filter by indeed using nested for loops to iterate through the collection and checking against the source.

Step 5. Now we write the logic so that when we iterate through the collections to check if the values of the sourceKey (the last name) match. Filter accepts a boolean value and normally outputs the items that are true to the logic and removes those that are false. In MDN's example, if the function checks for all the strings in an array greater than a length of 6, it will only return an array with those strings that are true to the function.

So I initially had in the following in my if statement:

if (obj[sourceKey[i]] === source[sourceKey[i]]) {
return true;
}

Success!.. or is it?

It solved the first and second test case but not the remaining.

Why!?


Well, my initial answer also returned any of the whole object in the collection if it matched one single key+value pair from the source, whereas it should only return the object if it matches all key+value pairs in the source. So just because I match 1 key+value pair in the source, it returned the whole object. This is obviously not what I want if there is more than one key+value pair in the source.

This is also where I spent most of the time puzzling through and could not get why it was not working. I tried a few different things that did not work out. So after an hour to trying, I peeked at the answer and saw right away... that it was reversed on their end. I applied it to my answer and of course it solved right away!

But why?

Step 6. Since filter accepts a boolean value and returns the bits that are true,  the logic should identify the objects in the collections array doesn't match all the key+value pairs in the source first and mark them as false (so it is not included in the output) then return all else as true after the for loop.

for (...){
  if (obj[sourceKey[i]] !== source[sourceKey[i]]) {
    return false;
  }
}
return true;

That's it. I have such a hard time even considering this route in using filter() or map() to define items as false first and return all else true as a way to filter more specifically. I am hoping I get better at this with time!


Tuesday, July 2, 2019

Day 086: Intermediate Algorithm Scripting (FCC)

I like the new FCC redesign! (recolor?)
I just finished the Functional Programming section on FCC. It took a few days to get through. I get why it is useful, but dang, it is a lot to take in. Callbacks seriously gets me cross eyed. And then when you add all the (new to me) methods like forEach(), map(), filter(), reduce() etc., it is a lot to take in!

At any rate, I am now heading into the Intermediate Algorithm Scripting section of FCC. I am trying to apply the Functional Programming principles to solving these challenges, so it is taking a bit longer to work through the problems.

What really helped me learn in the past was to collect a massive sheet of notes that I may or may not refer back to, but the act of putting it somewhere seems to help me understand it better some how? Or at the very least, it is good reference material. So here it is.

Intermediate Algorithm Scripting: Diff Two Arrays
I solved something similar in Edabit, but like I said, I wanted to get more practice in with the methods am not yet familiar with. I got that I needed to concat() the strings and knew filter() was the likeliest method that would help me find the answer, but I had some help from the Internets and StackOverflow to get the conditional statement correctly with the use of ! and includes() which I am not yet familiar with, nor would it be something I would have thought to use right away. I also poked around with trying to figure out how to refactor it a bit into all arrow functions, but rather move on to the next problem after a few failed attempts.
function diffArray(arr1, arr2) {
  var filterUnique = arr1.concat(arr2).filter((elem) => {
   if (!arr1.includes(elem) || !arr2.includes(elem)) {
     return elem;
    }
  })
  return filterUnique;
}  








Monday, July 1, 2019

Day 085: Finding the Sum of Consecutive Numbers with Javascript (Easy Mode w/ Carl Gauss)

While I am still digesting all the information from the Functional Programming section in FCC, I started to poke around the Intermediate Algorithm Scripting section. Low and behold, the first challenge was to Sum All Numbers in a Range.

I know that FCC wants us to do a loop, but that's boring since' I've already done a type of problem like this at least twice in Edabit and Codewars. After solving the problem there I was able to review how other folks solved this problem and recall that a few have used a formula, so cue up Google to search around. Gauss on Arithmetic Sequences hit the spot! The site goes into length about the formula and why/how it works. But I found what I was looking for here:



Where n is the number of integers.

Or for the purpose of applying it to the problem, I will use the below simplified formula.




And below are two versions of the answer. (Equations created with CodeCogs)

function sumAll(arr) {
  let min = Math.min(...arr);
  let max = Math.max(...arr);
  return ((max - min + 1)/2)*(min + max)
}

const sumAllCodeGolf = (arr) => ((Math.max(...arr) - Math.min(...arr) + 1)/2)*(Math.min(...arr) + Math.max(...arr));

Easy peasy! I think it's still good to practice writing out the loop as well. However, I am at the point where I've done enough of these arithmetic challenges that I'm getting clued into the fact that there is likely a formula for most things. If it doesn't break anything in JS, why not use it?

Quick Retrospective

Since it is Day 85 and I am 15 days away, I figured this was in order.

I know it is not recommended to do this, but compared to other folks that started around the same time I did, including some of those with zero HTML+CSS experience, I feel like I am about a month or two behind them in terms of progress. If we're using FCC as a yardstick, they're all in and around the Data Visualization section and I am still stuck in the Algorithm and Data Structures.

However! I am aware that the working like a Japanese salaryman hours that my day job demanded ate up 2.5 weeks in May and then getting into the funk due to the stolen phone/invasion of privacy last month severely demotivated me for another 2 weeks or so. I also took a long detour into Udemy courses (which I still plan on finishing) as well so FCC is not the best yardstick really. I guess that works out to be why I am "a month behind."

We all know the reasons why you should not compare your current self with someone else. Everyone learns differently and may have other circumstances in their lives that may help or hinder progress. Someone spending time between semesters at their parents home, covering their room and board will probably have more time to learn than I would since I have that day job eating up 9+ hours of my weekday (if you add in commute time). And I am probably better off in terms of being able to dedicate time to learning than a working parent with kids (and kudos to them!).

But the reason I follow these folks is not only for the camaraderie, but because I find myself feeling pretty hopeless and demotivated and I actually feel like the comparisons actually help motivate me! What it boils down to is that they are able to dedicate a whole lot more hours then I can (whatever their circumstances) whereas I sometimes only squeak by with the minimum 1 hour a day (or less on a handful of days). It makes me want to find ways to get in more hours! In fact, this was the reason I got out of my funk from last month.

Also seeing someone else's progress is extremely gratifying to me as well. The thought of "I can get there too as long as I put in the time!" is the first thing that crosses my mind.

So as long as you are aware that this is not a race, I don't think comparisons are inherently a bad thing. There are always ways to turn it on its head and use it to your advantage.


Tuesday, June 25, 2019

Day 079: Accessing Objects with Variables

Still working through the FCC Javascript Algorithms And Data Structures section and I am going through them pretty quickly thanks to all the practice I got on Codewars and Edabit as well as Angela Yu's Bootcamp (which I still haven't finished by the way. Currently at 90% done... need to finish soon!). I am hoping to get the certification for this section sooner rather than later. No specific date, other than "soon". Whenever I list a date, I seem to jinx it where something shitty occurs and derails me for a bit.

But I digress. So I also managed to finish two of the projects for the certification, the Palindrome Checker and the Telephone Number Validator (Regex). I think they are the two easier projects (and I actually enjoyed regex?) so I expect to spend a bit more time working through the other ones. I already looked ahead and they seem pretty difficult!

Anyways, I just want to plop the bit below as a reminder to myself on how to access through the keys of an object, in the below example is by using the For In loop (which I need more practice with).


let users = {
  Alan: {
    age: 27,
    online: false
  },
  Jeff: {
    age: 32,
    online: true
  },
  Sarah: {
    age: 48,
    online: false
  },
  Ryan: {
    age: 19,
    online: true
  }
};

function countOnline(obj) {
  // change code below this line
  let count = 0;
  for (let user in obj) {
    console.log(obj[user]["online"])
    if (obj[user].online === true){
    count++;
    }
  }
  return count; 
  // change code above this line
}

console.log(countOnline(users));

I got really tripped up with this one. Just a note to myself that I need to use brackets when accessing the key values with a variable!

obj[user]["online"]   or   obj[user].online

It was something I was banging my head over for about 30 mins. /bleh

Oh yeah, I changed the blog subdomain from anncc.blogspot.com to anncodes.blogspot.com. Not sure why I didn't think of that to begin with..


Wednesday, May 29, 2019

Day 053: BTDT Tip Calculator & Bill Splitter - using parseFloat, toFixed & building it in order to make it work!

Yesterday, I took take a short break from the bootcamp for a day to let the information sink in a bit (see active and diffuse learning). So what better time than to do my next BUILD THE DAMN THING project. It is a handy tip calculator & bill splitter that I probably spent way more time on that I should have.

See the Pen Tip Calculator/Bill Splitter by 4nn (@4nn) on CodePen.

Some Things I Learned

I guess I already knew these things, but it was more so putting it into practice and getting to experience the joys of parsing strings to numbers to strings to numbers so the formula would work.

I initially thought this would be quick and easy since I banged out the formula in the console in less than 5 mins.

parseInt(), parseFloat(), .toFixed()

Of course the console just deals with the parameters as numbers. It is a different story when you are pulling values from the DOM, which would output those numbers into a string. You can't really do math with strings!

So I became intimately familiar with the parse functions to get those strings into numbers. (Good to know when I tackle the building a calculator project)

parseInt() parses the value into an integer. I used this in the beginning since I was testing with whole numbers.
parseFloat() parses the value into the floating point number (with all the decimals and such).

Once that was all set, I later used the .toFixed() method to get the numbers into 2 decimal places.

Voila! The math actually worked with the DOM in codepen!

So I go about to add in the conditionals and error messages and such, but the conditionals did not work because it was essentially asking if the preTipBill === NaN. Why did it keep coming up as NaN even though the math worked out previously? Enter frustrationland!

My husband probably noticed my annoyance after some time which was his cue to help (of which I didn't ask for his help, but recognize that I need to get better at knowing when to ask). So he identified that I was doing too many things at a time before calling the if statement. I was assigning the DOM values to the variable and then reassigning the variables to parseFloat().toFixed() and then setting the condition statement. It looked something like this:

 let preTipBill = document.getElementById("preTipBill").value;
 preTipBill = parseFloat(preTipBill).toFixed(2);
 let tipPercent = document.getElementById("tipPercent").value;
 let splitBetween = document.getElementById("splitBetween").value;
 splitBetween = parseFloat(splitBetween).toFixed(0);

 if (preTipBill === "" || tipPercent === "" || preTipBill.length === 0 || tipPercent.length === 0) {
  ...
 }

Of course that mess was then checking the if conditionals to preTipBill === NaN which is not what I want especially when trying to reassign blank splitBetween values to 1 if the user opts not to split the bill. Anyways, once he pointed that out, I got it right away. Like, RIGHT AWAY. Rookie mistake!

  let preTipBill = document.getElementById("preTipBill").value;
  let tipPercent = document.getElementById("tipPercent").value;
  let splitBetween = document.getElementById("splitBetween").value;

  if (preTipBill === "" || tipPercent === "" || preTipBill.length === 0 || tipPercent.length === 0) {
    document.getElementById("output").innerHTML = "Please input all required amounts!";
  } else {

    preTipBill = parseFloat(preTipBill).toFixed(2);
    splitBetween = parseFloat(splitBetween).toFixed(0);

I needed to reassign the values LATER, preferably once the condition is met. Just moving the reassignments fixed the whole thing. Sheesh!

In working through all the projects in the Angela Yu Web Dev Bootcamp, the location of the reassignments were sort of laid out for you when working through the projects and it made a ton of sense at the time, of course. But it really isn't until you've been frustrated and 😬 over it for an hour that it really sinks in. The ORDER of your code matters! I found this to be a very valuable lesson.

On a side note: it's my mom's birthday this Saturday and I'll definitely be pulling out this little calculator at the end of the meal!

Here's the User Story
  • user inputs total initial bill
  • user inputs desired tip amount
  • user gets error message if initial bill and tip amounts are missing
  • display the tip subtotal
  • display the total amount
  • user can opt to split the bill, input number of people to split it with
  • display the per person initial bill
  • display the per person tip and total
  • if user does not split bill, only display the tip & final total
  • have button calculate and clear all

Tuesday, May 28, 2019

Day 052: Personal Bootcamp Debrief

So it's Tuesday now and the long weekend has come and gone. How did my personal bootcamp go?

It was really tiring, but a GREAT experience. I didn't want to spend too much time blogging about it while it was going one since I wanted to dedicate most of the time during the weekend to coding and learning to code. I posted some thoughts on instagram during the weekend.

Day 1:

Day 3:

The plan is to do something like this once a month and maybe drag some folks from my accountability group into it as well, if they want to jump in for a day or so.

As for how far I got through the material (Angela Yu's Web Dev Bootcamp), I was at 23% of the course having just finished the Bootstrap section when I started the weekend. I ended the weekend at completing 66% of the course and am into the first few videos on JSON and API.

Sort of Daily Breakdown

I was mentally wiped out the first day since it was pretty much a continuous 8+ hours of learning and coding.

The second day was much better because I took a long break in the middle so it was like 2 medium sized coding sessions vs one big long one on the first day. It was also mostly working on a project that day (building a Simon Says game) so that added variety. I also kind of stayed up until 2am in the morning that evening watching more of the videos after finishing the project because I felt like I was on a roll.

The last day was a bit shorter (since I got in those hours in the AM ), so it was not bad in terms of total hours required for the daytime. I did do the minimum number of hours on the last day so I can enjoy the long weekend and let my brain rest for a little. In all, I did clock in bout 25.5 hours of learning and coding in the past 3 days.

What I Learned

I feel like I learned SO much! The three big things: being more comfortable with the DOM, being introduced to NodeJS, and finally learning the CLI/Git/Version Control. The next bits would be to get through the API section (which is also very cool!), moving on to databases, RESTful API, and authentication and security. I would like to finish the course by the end of this coming weekend, but we will see how that goes since it depends on how much time it takes to get through the projects.

Hi NodeJS. I am so excited to meet you!
I must say, I really enjoyed the projects in this bootcamp. When she introduces you to a concept, there is a bit of code-along happening. Then there's the pausing before each mini challenge so you can work through the concepts on your own before you unpause and she goes over it. For the big projects (what she calls "boss level challenges), she lays down the to-do's for each step and you tackle them one by one. At the end, she goes over the whole project. I opted to not review her solutions unless I feel really stuck (and am happy, but annoyed with myself to say that I peeked only once during the Simon Says challenge).

You know I already had that problem before where the initial look at the code makes me wonder how in the world I can ever get to that point. But those step-by-step to-do requests really help remind me that this is what programming is all about. They are all little steps to get to the final product. And when your app works and you look back at the code, everything actually makes sense!

What's Next? 

I know I haven't finished Angela's course yet, but I am already looking ahead. Here are my next to-do's:
I added another intro-to style course to the list, Andrei Neagoie's ZTM because he has sections that cover React & Redux which I feel is something important that is missing from Angela's course. His projects also seem really interesting too. Colt Steele's Web Dev Bootcamp course also ranked high, but he is missing React & Redux so I did not really consider it. I might consider Colt's Modern React Bootcamp course in the future though.

For Andrei's ZTM course, I will skip the parts that I am comfortable with (HTML, CSS, JS basics), use the parts I am not yet comfortable with as review on 2x speed, and delve into the projects for the experience. I am also interested in his more intermediate course, the Complete Junior to Senior Web Developer Roadmap (2019) and figured I ought to see if I like his teaching style before jumping into another 30+ hour course. Use the coupon code LEVELUPZTM to buy his course fo $10.99 without having to wait for a sale.

The focus of the list is projects, projects, PROJECTS! Which is why Wes Bos' JS30 is on the list as well as the Odin Project. I was actually slowly going through TOP Web Dev 101 as bedtime reading, so I am about 33% done with it already. It follows along nicely with Angela Yu's bootcamp contents this past weekend. In TOP, I am skipping the parts related to Ruby or Rails, but might revisit that in the future. TOP just seems to have some really great projects and the curriculum is constantly being updated (contrary to what they say on the internets).

In the middle of all this, I do intend to do the challenges and projects on FCC as well. I would like to get the full stack FCC certification eventually! FCC is kind of where it all started, so of course it is always on the list. I do admit that the website alone was not enough for me to understand the material (sometimes the wording of the challenges confused me) hence my branching out to Codecademy, Lynda, and Udemy which has been working well in helping me learn.

Okay, this post was a lot longer than intended, but it is really good to create a roadmap for myself to tackle in the next few months. This also helps to know what I am doing for my next Personal Bootcamp!


Thursday, May 23, 2019

Day 046: BUILD THE DAMN THING - A Simple MadLibs

I'm pleased to present my first project from (mostly) scratch: a simple and silly madLibs app!

See the Pen Simple Madlibs by 4nn (@4nn) on CodePen.

It's "mostly" from scratch because I had to look up the DOM syntax and later encountered some issues with the HTML5 form inputs, namely using <input type="button"> vs <button>. I need more practice in understanding the DOM. While I understand that part of being a good coder is getting good at asking the right questions to look up stuff, but I can't wait until the day I actually know the syntax well enough to not need to reference documentation!

Here's the user story for the app:

  • Allow user to input various words
  • Generate random madLibs sentence
  • Allow user to clear the madLibs sentence
  • Allow user to clear input values
  • If any input is empty, prompt user input 
  • Pretty up UI with some bootstrap practice

In all I spent about 2 hours on it including the Bootstrap bits. I am not including the time I spent at the end of April trying to create this. This was right after I finished up the Practical JS course and was attempting to create the madLibs in the console first (like the course) and then move it to the DOM. I set up my workspace in VSCode and got to work on the JS file. Unfortunately, I ended up just confusing myself and making it more complicating than it should be and got frustrated and gave up. You know the old adage of putting the cart before the horse? Yep. 

But after watching all those videos during crunch time at work, I got a bit more confident to give it another go. Since it was simple enough, I figured starting it in Codepen was enough and it was! 

I have to admit, even getting to the point where I knew I had to start building stuff scared me. I couldn't put into words why I felt the fear of starting the project, but in retrospect I think it's the sentiment of "I can't fail if I don't start!"

Once I decided to restart the project, it took a whole day to get over the fear. I was procrastinating by doing chores or watching more videos. Once I realized what I was doing, I took to repeating to myself to:

BUILD THE DAMN THING! 

JUST BUILD THE DAMN THING!

And then I did and it wasn't terrible! Sure, I needed to reference some materials and some parts didn't work at first, but it in the end, it was resolved and it works more or less as I envisioned it. It even took less time than I thought it would (I had estimated 6 hours lol). I also reminded myself to take it one step at a time and that helped a lot. 

Knowing how I am, I am probably going to keep having the same fear as my ideas for projects get more complex. But I just have to BUILD THE DAMN THING and just keep chugging along. 

The next projects to work on is a tip calculator, day counter (so I can correctly get my #100dayofcode number), a Tabata timer, and an actual calculator. Baby steps! 


Saturday, May 18, 2019

Day 041: Making it Rain (Khan Academy)

Crunch time at work is nearly coming to an end (one more day on Monday), HOORAY!

On average, I worked about 65ish hours per workweek for the past 2.5 weeks. The weekends were not any better since I spent much of the time catching up to sleep or trying to de-compress from the workweek (and also doing some work on the weekends as well, bleh). Not only were the hours long, but the work is really freaking stressful and it involves a lot of literal running around, making snap decisions and solving things.

I have been so exhausted by the end of the day that it has been quite challenging dedicate much time to learning or even retaining any information when I do get to put in more than an hour/day. I admit to coming really short on some days (like 15 mins of tutorial videos before bed and passing out with my laptop by my side, oops). I do get some snatches of reviewing/reading materials on JS here and there during bits of down time at work, but I am not sure how meaningful that is when one is constantly interrupted.

Given how tired I am and how little time I have at the end of the day, the best I could manage was passively consuming videos here and there. Most of the actual coding I did was with the Khan Academy Intro to JS: Drawing & Animation challenges that they have in the course.

The course was such fun and the challenges were really cute! Really a breath of fresh air full of colors and movement at the end of a long, stressful day. Their most complex challenge in the course (and my favorite) so far has been the Make it Rain project. It starts you off simply enough and becomes a bit more complicated in each step. I probably spent about 3-4 hours spread over a few days working on it during quiet times at work or right before bed at home. By the end of the exercise, I was very surprised with all the code written that actually worked and refactored a few times. And the best part was that it all made sense to me!

Make it rain!
I remember looking at someone else's spin-off at the start of the project thinking about how it was impossible to do with my tired brain and limited time and that I should save it until after crunch time at work to be able to make sense of it. I know many people have said this before, but this was the challenge that demonstrated it to me: as a whole, it can seem monumental but when broken down into small parts, it's possible to do!

I initially shied away from KA because the content was geared more towards children and teenagers and I thought it may be too childish for me. Because after all, coding is serious business! *scoffs*


It's great for anyone, particularly those who may be struggling with some of the basic concepts. I honestly think they might have the best approach to introducing brand spanking new learners to JS. I especially like their explanation on object oriented design and object inheritance, the best I've seen yet (I actually understood it! Do also view the videos as well). The instructors teach without making assumptions about you and seem so happy and enthusiastic about it (since they're teaching to kids after all). It doesn't make you feel too bad if you may not get it 100%. I am actually planning on doing a few more of their other courses as fun little breaks here and there from the "serious" learning.


Sunday, May 12, 2019

Day 035: Passively Consuming More Online Courses

Not much to report due to work obligations taking up a chunk of time (average so far have been 13 hour work days for the past week and half, 6 more days to go, /sigh) so much of my learning time have been passively watching the Lynda courses before bed.

It's not what I prefer because it is not active learning, but it is the best I can do at this time. I try to do what I can during down time at work, but the nature of my work is full of interruptions so at best, I can just review notes here and there.

For my to-do list from the last post, I did manage to finish off 2 courses on Lynda.com and I am working my way through the KA course (which has a split of videos and exercises, so I have been going through them a bit slower), and I added a few more bits and bobs to the list.

Note: all the Lynda.com links require a paid account (I get free access from my work). However, I have heard that some public libraries allow access to Lynda if you are a member, so check your local library to see if they offer the access!
  • Lynda.com JS for Web Designers w/ Joe Chellman: has a great quick intro to the DOM as well as using the Google Maps API in one of the exercises. It's a relatively short course, but pretty good for the continued exposure and the intro to DOM if you haven't been introduced to it yet. 
  • Lynda.com Learning the JS Language w/ Joe Chellman: this is more of a refresher for me. I am finding the nested loops to be the most challenging for me right now and I enjoy seeing how different instructors go about explaining the concepts in different ways to really drill it in my head. 
  • Khan Academy Intro to JS: Drawing & Animation: this is just a fun JS tutorial refresher. It's aimed at teaching kids so there is a lot of whimsy to it (and much appreciated when my brain is fried after a long day at work). This particular course uses the Processing.js library to teach the concepts of JS with drawings and animations so it was a fresh take on the basics and is admittedly my real first use of a specific JS library. I am almost done with this course. 
Here are the addons: 
  • Lynda.com Coding for Visual Learners: Learning JavaScript from Scratch w/ Engin Arslan: After finishing the other 2 Lynda courses, I started on this one. However, I feel like it covers much of the same content as the KA Drawing & Animation course (although he uses P5.js instead of Processing.JS), so I am putting this on hold for now and maybe revisit on 2x speed as a refresher in the future. 
  • Lynda.com Learning ECMAScript 6 w/ Eve Porcello: I just started this one. I haven't gotten too far, so not much to comment on right now. Since I am moving on to the ES6 section on FCC, I figure this is good to watch to get more familiarity with Modern JS.
  • Lynda.com JavaScript: Functions w/ Ray Villalobos: Haven't started this one yet, but it is short enough to go on the list and would be a good refresher, I think. 
  • Lynda.com JavaScript: Events w/ Ray Villalobos: Haven't started this either. It is also another short course and I won't mind getting a closer look at events. I also heard Ray Villalobos is an excellent instructor so I am eager to check out his courses. 
I think all of the above will keep me occupied until I am done with having to work like a Japanese salaryman. Once crunch time at work is over with, I slowly start going through a recently purchased Udemy course, the Complete Web Development Bootcamp w/ Angela Yu. There was the Mother's Day sale going on at Udemy for $11.99 so it was hard to pass up such a highly rated and widely recommend course.

Have to support other Asian women, yanno!
Whilst I am still a bit shaky on some of the JS fundamentals, I am getting impatient to start moving on with the material and I shouldn't just languish in the JS basics forever. It is only convenient to do so now because of the work situation.

But once work is not an issue anymore, the goal is to follow along with Angela's course. It has 42 hours of course time and basically covers everything in the FCC curriculum.

If I have unlimited free access to the Lynda courses, why did I decided to shell out the cash for a Udemy course? While the Lynda courses are great, they're a bit all over the place and lack the consistency of having a single instructor and a focused curriculum. True, they have something called "Learning Paths" but I found I do have an adjustment period to each new instructor and they vary in the projects and challenges each course offers. I also want something that more closely follows the path in FCC so I decided to go with Angela's bootcamp. Honestly, I spend more than the cost of a Udemy course on lunch at work so that bit of money on buying a structured program is worth it to me.

I've just gotten through the intro section and I have found her to be a very pleasant and engaging instructor so far. I'll probably 2x speed through the HTML/CSS sections only watching those parts and then slow down and start coding when the Bootstrap sections start.

I do intend to go through her course at least 2x and may consider other well known and highly regarded Udemy bootcamp courses if I feel like I need more exposure to the basic web dev stacks, but I am hoping her course will be enough. I still haven't gone through a second iteration of Practical JS yet and I still want to soonish. I think it will be interesting to see how much better I will be able to follow along with him now that I understand JS a bit better.

I thought I was more of a read-along/screenshots type of learner. But since I was kind of forced into the video habit due to work, but I am finding a great deal of enjoyment out of them. And yes, I do believe the repeated exposure has really helped me understand the concepts even though I have not been able to psychically code much.


Wednesday, May 1, 2019

Day 024: Javascript Resources

I am still spending at least an hour coding/learning to code each day (the average so far has been ~1.5 hours/day of focused learning). It has been slow going and I feel like it's taking a long time, but I want to be deliberate in absorbing all the information and keep getting more exposure to it.

The list below are all the resources that have been referred to me by various sources and people on learning JS and I figured here's as good as any to list it for reference later. I will probably slowly go through one of these resources in the next 2 weeks.

Today is the start of my busy season at the day job where I'll be working anywhere from 12-15 hours a day (yeah, 7am-10pm is not out of the realm of possibility) for the next 2.5 weeks. Study time will be really limited to the bits of slow time at work because I am pretty much wiped out once I get home. I am probably not going to be able to do much focused learning and have a few video/courses lined up to watch when I am able to. It's not the best kind of learning (I need to be more hands on), but it's the best I can do unless I want to forgo sleep. 😑

That said, I am focusing on more videos for the convenience vs projects for now to keep the exposure up. Here's the plans in the meantime:
Of note is that I finished Practical Javascript on WatchandCode.com last week. I highly recommend it for anyone just starting out. I intend to go over the tutorials another 2-3x again for more practice, so you can add that to the list above.

Lastly, on a whim, I signed up for a 21 day coding challenge with Lighthouse Labs. The grand prize is a trip to Boston, MA! Woo! But only for Canadian residents. Since I am already in Boston, I think I'm A-OK with not winning anything, 😊 but am joining for the learning experience and to work through problems with my accountability group. 


Wednesday, April 24, 2019

Day 017: Still in Basic Javascript

I am still having trouble getting the basics to stick. It's mostly the "grammatical" parts of the syntax where I have some difficulty remembering when and where to pull/place parameters, functions, or whatever into where ever to make a line of code work. It gets even more confusing when things start to nest, like functions in objects or what the cool kids call methods. I think I need to make some obnoxiously long names just to help myself remember where things belong.

I know that I need to get used to what they are and recognizing the pattern of where to put things. Or remembering what the definitions of certain things are when an instructor says, "now we call this parameter from the xyz" that I often have to look up what xyz is (again). Ugh. Just all part of the learning process. My coding cheerleaders (the husband and some programmer friends) tell me that I will get used to it eventually and that it will become second nature then.

So I need to just keep at it to familiarize myself with js. With that, I've taken even more detours from FCC and am working through the following:
  • WatchandCode Practical Javascript with Gordon Zhu - who is my freaking hero right now because his teaching style is effective and not like anything I've encountered so far; I will likely work through the same course with him a few more times to hammer the concepts in; I am also heavily considering subbing to his premium course once I am comfortable enough with the the basics. He is just that good and highly recommended for anyone trying to learn js basics from a free resource. 
  • Lynda.com JavaScript Essential Training 
  • W3Schools Javascript Tutorials 
  • Codecademy Intro to Javascript
I am in various stages of completion with each of them but should be done with most, if not all by this weekend. I'm at the point where I don't think repetition is doing enough, so I might as well try to apply what I've learned so far on my own and stumble and self correct as needed.

So far I have the following on the to-do list for this weekend. 
  • Madlibs game
  • Tip calculator 
  • Pomodoro timer
It feels like I've been struggling with this for a long, long time now, but it's actually been less than a week in starting the js basics. I need to be patient and get through the weeds first.

P.S. I guess I need to create some kind of js cheat sheet. MDN on js grammar and types for anyone interested. Also a handy video from DashingD3js on functions and callbacks that I will need to watch a few times. Lastly, read Javascript for Cats to keep absorbing the basics. It's super cute!

Sunday, April 21, 2019

Day 014: Order & Syntax

I started on the Javascript part of the FCC exercises and was going through them pretty quickly due to a tiny bit of experience in js years ago and going over the Programming Foundations: Fundamentals with Simon Allardice.

That is, until I got to the Stand in Line exercise.

I am probably going to get some terminology wrong but I am explaining it in newbie/layman terms as I understand it.

So for this exercise, I knew I needed to push() and shift() - easy enough concepts. But I just could not get it right. It could have been the confusing-to-me instructions or the existence of the testArr. But after about 30 mins of banging my head over it, I am ashamed to admit that I looked at the hint which gave the solution. /bleh

Even so, I was still not understanding why the solution was why it was even after another 30 minutes of trying to dig up the reasoning. That feeling of maybe I'm not smart enough started to creep in so I decided to take a break. After lunch and a quick gaming session, I still wasn't feeling confident enough to go back to figuring it out. So I hopped on the indoor cycle for an hour and watched the first half of the JavaScript Essential Training with Morten Rand-Hendriksen (who is also great as well!). I realized I might be missing something and just needed to keep familiarizing myself with the rules.

I got to this part and just had to take a screenshot. Cue the eureka! light bulb.

Morten is my best friend now.
One of the things that tripped me up was that I was trying to fit the testArr variable into the standInLine function even though they didn't have much to do with each other at that point. I was even including numbers in my push() and shift() even though the code had not even assigned numbers yet!

The initial task was to create the instructions inside the functions first. I should have looked closer on the arr and item parameters from the function. Which is what should be used in the statements inside the function body. /doh!

function nextInLine(arr, item) 

The testArr was defined after the function and then later called upon in the display code that made use of the standInLine function. Remember, the function are instructions that can be used again and again by other variables. Even if you create a new variable of testArr2 and assign 11, 12, 13 to it, you can later use the same standInLine function to remove the first value and add in a new value.

After you get the solution, give the below a whirl after to see what I mean:

var testArr2 = [11,12,13]; 

console.log("Before: " + JSON.stringify(testArr2)); 
console.log(nextInLine(testArr2, 14)); // Modify this line to test 
console.log("After: " + JSON.stringify(testArr2));

I forgot that and tried to cram everything together. Judging from the forum, a whole lot more people than just me made the same mistake. The Python tutor tool for Javascript also really helped visualize the computing.

I do have a tendency to put the cart before the horse (like, I'm one of those people who does not mind spoilers and may even look them up myself), so I just have to remember that the order is really, really important in Javascript and every other language out there and I really need to stop trying to get ahead of myself.

Lastly, I included Syntax in the blog title because I am finding that most of my other mistakes are syntax related as opposed to logic mistakes. I am the queen of typos. I also often find myself missing a bracket or quotation here and there that breaks the code. I am not sure if there are ways to improve on this other than relying on the text editors or ide's to help me on preventing name typos and getting into the habit of opening and closing things before adding in the body... I am all ears if you have suggestions!