"Return Statements, DOM Tweaks, and Small Fixes That Made a Big Difference"


Today was all about small wins — those moments where something finally clicks after staring at it for way too long. I’m still in the early stages of learning JavaScript, but each day adds a bit more clarity. Here’s what I worked through:
🧠 Understanding return
vs console.log()
This was a lightbulb moment. I used to think they kind of did the same thing — show you the result of something. But that’s not the full picture.
console.log()
is like saying something out loud. It just tells you what the value is.return
is like handing the value to someone. You can catch it, store it, and use it later.
For example:
function getFastestRaceTime() {
if (player1Time < player2Time) {
return player1Time
} else {
return player2Time
}
}
let fastestRace = getFastestRaceTime()
console.log(fastestRace)
Here, return
gives me the value. console.log()
just lets me see it.
🐛 Debugging a Scope Issue
I wrote a totalRaceTime()
function and forgot to declare the sumOfRaceTime
variable with let
. That made it global by accident — which could lead to issues later on if something else messes with it.
The fix was simple:
function totalRaceTime () {
let sumOfRaceTime = player1Time + player2Time
return sumOfRaceTime
}
Lesson learned: Always declare your variables properly to avoid surprise bugs.
🃏 Working on the Blackjack Project
I’ve been building a simple Blackjack game, and I finally got the basic flow working: drawing cards, calculating the sum, and updating the UI based on the outcome.
Here’s a snippet from where I left off:
function newCard() {
let card = 6
sum += card
cards.push(card)
renderGame()
}
Right now the card value is hardcoded to 6, but the next step is to make this dynamic by writing a getRandomCard()
function. Still, I’m proud that the game works — it updates the DOM, responds to events, and feels interactive.
🧩 Small But Important Discoveries
Using
+=
instead of=
when building strings:greetingEl.textContent += sentence[i]
This let me append new words instead of replacing the whole thing each time. Little things like that really shape how the app behaves.
I also practiced looping through arrays to display card values:
for (let i = 0; i < cards.length; i++) { cardsEl.textContent += cards[i] + " " }
That’s how I’m building up the visible cards on the screen.
🎯 What’s Next?
Tomorrow I want to:
Implement the
getRandomCard()
function.Refactor the Blackjack game to make the logic cleaner.
Play around more with conditionals and maybe even try adding a “restart game” button.
Every time I debug something or make the code cleaner, I feel like I’m leveling up a little bit more.
I think I want to do this a bit more. Fingers crossed I show up and actually do it.
Its good practice for documentation to be fair.
See you tomorrow.
Subscribe to my newsletter
Read articles from Oseluonamen Irabor directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Oseluonamen Irabor
Oseluonamen Irabor
code bad. but i'm badder!