Baby Stepper – 94 of 100 Days of Code
The little wins will take you further than you think.
I started a codewars challenge called Keep Hydrated. In the example, a cyclist drinks a certain amount of water over time. With the numbers given, create a program that calculates how much water they drink after a certain amount of time.
PSEUDOCODE
My pseudocode for this challenge goes:
- Prompt for time
- Round time down to an integer
- If even, divide by two for liters
- Else, subtract one first, THEN divide by two for liters of water
- Display the liters of water drank.
Everything went great! That was, until I ran into a weird error in Visual Studio Code. I got this warning that wouldn’t let me save my work.
THE BUG
I tried editing the file security settings, but my account was still listed as an owner. In the end, I restarted my laptop and everything worked as expected. I could finally save!
GETTING INPUT
Kotlin uses a method called readLine() for obtaining input from the keyboard. I tested this in another program where I prompted users to enter their name and displayed it
ROUNDING DOWN
Kotlin has a function called .toInt() which converts decimals to integers. It truncates the decimal, meaning, it takes the number and only keeps the digit in the ones place. 1.5 becomes 1, 6.7 becomes 6, etc. In other words, it rounds down.
Getting back on codewars was a great move. No point in waiting to build apps before I use Kotlin. I can practice the language in the mean time.
I picked a good challenge to start with. It’s simple and I figured it out pretty fast. I wish I had started doing this sooner. Not to mention, working on this led me to solving that weird VS Code error. Even the little things bring experience!
Moving forward, I’ll start doing coding challenges regularly to keep my skills sharp.
Building big projects is important, but these small victories are just as necessary.
Join the mailing list to see updates like this every week!
Coding Fanatic
Sources:
Codewars Keep Hydrated Codingkata
Image by Free-Photos from Pixabay
Image by Chuk Yong from Pixabay