DEV Community

kevinLearnsToCode
kevinLearnsToCode

Posted on

My First Coding Blog

Hey everybody!

Everybody? Right. Like I have a huge following for my DEV blog. Let me try again.

Hey fellow cohort members!

So I decided to just pick a lab and write about the process of completing it for my first blog. Very exciting.

And the lucky lab is... Phase 1 Review Strings Lab!!!

Since this is review of things I should have already learned in the prework, I'm just going to fork the lab, clone it, open it in VSC, take a look at index.test.js and then go from there.

OK. So the test indicates I'll need a current user, a few different welcome messages and.... yeah, I'm just gonna make life easy and run learn test before I write any code and see exactly what they're looking for.

10 failed tests! Great start.

So, the first failed test is "currentUser is not defined". That one's easy enough.

const currentUser = "Kevin Price";

My own name... the vanity.

learn test.

Alright. One passing test. Let me see if I can knock a couple of tests out in a row. I don't need this blog to be ten pages long.

Looking over the failed tests I need a welcomeMessage that includes currentUser and an exclamation point. Easy enough.

const welcomeMessage = "Welcome to Flatbook, " + currentUser + "!";

...should I have used interpolation? I think I probably should have used interpolation. But, it's just review... Let's just run learn test again and see what happens!

HA! Four passing tests! Suck it interpolation!

Six more tests to go. Let's see what's next.

excitedWelcomeMessage. All Caps. Contains currentUser. Exclamation point. How about?

const excitedWelcomeMessage = "WELCOME TO FLATBOOK, " + currentUser + "!";

Let's see!

Six tests passing! Not bad, but it looks like there's something wrong with the code I just put in.

Ohhhh. The currentUser name is also supposed to be capitalized. Wait. I know this. There's an easy way to do this with a string... do I keep trying to remember or just google it? Life is short. I'm googling.

toUpperCase!! Yep. That was it. OK so now do I need to do a separate const for the uppercase name? This is where I'm regretting not using interpolation. Or can I just attach it directly to the...

const excitedWelcomeMessage = "WELCOME TO FLATBOOK, " + currentUser.toUpperCase() + "!";

HAHAHAHAHA!! Seven tests passed! Now let's see what these last three tests are.

shortGreeting and just the first initial of the currentUser name. OK. So... can I just treat currentUser like an array? Don't strings usually behave like arrays? Right? Seems a bit too easy, but...

const shortGreeting = "Welcome, " + currentUser[0] + "!";

10 passing!!!! Yes. Never a doubt.

Oh. And I now notice that the lab actually walks you through the process... and they wanted me to use interpolation. Oh, and I was supposed to use slice for getting the first initial. Apparently those would have made my code more flexible. Oh well. Maybe next time!

Top comments (0)