Coding Log — January 2nd, 2018 — Day 17

Coding Time: Half Day

Here’s what I did today:

Continued Learning JavaScript

Days like today are what cause a 6 month plan to turn into a 9 month plan.

The wifi was out for most of the day. I could’ve worked offline, but I just couldn’t get myself to. It’s already so hard to learn to code, and then I only had access to the book in Kindle form.

So, I downloaded the Markdown files and got a dedicated Markdown viewer now. I will be okay without the internet now. Especially after knowing that the book is pretty self-contained. The first program we write in the book is 30 lines! That’s a pretty big deal to me. There’s no “hello, world. You’re a programmer now!” here. At the same time, at no point (once I got my head on after the information overload from last night) did I feel truly lost writing this code. I just needed to look up at some of the examples of how to write the syntax for what I wanted to do. That was all within the chapter – no outside Googling involved.

For now, this is how I handle writing programs. I take it one tiny step at a time. I write (on paper) what I want to accomplish in plain English. Then, I reference the chapter to figure out how to do that. (I vaguely already had an idea of what I wanted to code up each time, but the specific syntax is hard to remember right now.) Then, I write it out. I test it using VS Code’s debugger. If it works, I keep going. Rinse & repeat until 2-3 lines reaches 30 lines.

I have to admit, I got pretty stumped around the time where I had to add functions into my code. Part of that was that I came back to it after 12 hours away. My flow of writing out what I wanted to do on paper just didn’t hold. I sort of brute forced it. But hey, I did do the bonus challenge of adding a prompt, so… That makes up for it?

Here’s my code for the practice program we had to do in Chapter 1:

const phone = 99.99
/*var bankBalance = 575.23*/
var total = 0
const accessory = 9.99
const TAX_RATE = 0.08

bankBalance = prompt( "How much $$ you got, man")

function calculatingTaxRate(total) {
  total = total + (total * TAX_RATE)
  return total
}

function dollarDollar() {
  return "$" + total.toFixed(2)
}

while (bankBalance > (phone + accessory)) {
  bankBalance = bankBalance - phone - accessory
  total = total + phone + accessory
}

total = calculatingTaxRate(total)

console.log(bankBalance)

total = dollarDollar()
console.log(total)

if (total < bankBalance) {
  console.log('Woo') 
}

else {
  console.log('Boo')
}

It’s a pretty complicated program, in my opinion! I think it’s really exciting that I did something like this on my second day of real dynamic coding without ever feeling truly lost.

After looking at the solution, I made a few mistakes writing my code:

  • I totally skipped over the Spending Threshold that was mentioned in the practice. I read it and thought it was just the bank balance? Oh well.
  • I do not use ANY comments. I know I have to use comments liberally, but I just don’t remember while I’m writing my code.
  • I missed a few other small things (making the accessory an if statement within the while), so technically my program ended up a lot more bare-featured than the example code. Oh well? I don’t know. I’m pretty proud of this. I don’t know if I should be.
  • I also have no clue if ; are supposed to be in JS or not? The book uses them, but my Linter said no??? I’m so confused.

So, there’s a new thing I’m trying to make my learning deeper. After I get the code right the first time, I delete it, and try rewriting it from scratch without all the copious referencing to the chapter I just read. Otherwise, how do I know if I really understood it?

It’s a 6-bullet instruction list, and guess where I ran into my first problem despite having already written the code before? Bullet 1. Great.

I think I understood what I had to do, but the syntax really slipped me up. I forgot {} around an if statement, for example. I forgot to put all the correct parentheses around a statement. It’s the kind of thing a Linter doesn’t pick up.

The only other spot where I ran into problems was with the tax function not returning a success message when it was clearly successful. I looked back at my own code (never the lesson), changed one line, and it worked.

I think this new method of rewriting an exercise a second time really helps develop understanding. I told myself I would write it 3 and 4 times until I got it without having to reference at all, but I think that might be overkill.

For now, here was the code for my second time:

const TAX_RATE = 0.08
const PHONE = 99.99
const ACCESSORY = 9.99

var total = 0

// I want to do these prompts but they don't work inside of VS Code, I will re-enable them in the browser after

spendingThreshold = prompt( "How much you wanna spend per phone, I guess??")
bankBalance = prompt( "How much $$ you got total tho")

/*var spendingThreshold = 200
var bankBalance = 648.93*/

function payTheGovt () {
	total = total + (total * TAX_RATE)
	return total
}

function formatNerd () {
	return "$" + total.toFixed(2)
}

while (bankBalance > (PHONE + ACCESSORY)) {
  bankBalance = bankBalance - PHONE
  total = total + PHONE

  if ((PHONE + ACCESSORY) < spendingThreshold) {
    total = total + ACCESSORY
    bankBalance = bankBalance - ACCESSORY
  }
}

total = payTheGovt()
/*total = formatNerd()*/

console.log(total)
console.log(formatNerd())
console.log(bankBalance)

if (bankBalance) {
	console.log("Woo")
}

else {
	console.log("Boo")
}

I know there’s extraneous console logs. I like it that way. It helped me keep track.

Tomorrow’s To-Do’s

Read through Chapter 2! I’m getting a bit of a jumpstart in bed tonight. I’m not going to be in front of the computer to do the code snippets, I’ll just be going through a bit on paper to avoid information overload tomorrow.

Comments can be sent via email.

Subscribe via RSS Feed.