JavaScript Baseball
Tags: javascript, react, programming, codenewbie
Published: 2021-04-10 15:40:05

# Do It Because It's Fun
Some advice I give to people a lot is once you have a good grasp on your preferred language you should build something you're passionate about or something you enjoy.

With new programmers a lot of the struggle is habit building. Getting into the groove of studying and learning takes time. And it's a lot easier if you're having fun while you're doing it.

Now the key like I said before is to try and create a project that you find interesting. You may be thinking, "But I only like nuclear physics... how am I going to write a program about that?"

The key here is not to build some elaborate project... at least not at first. You could create a project that asks you Nuclear Physics questions and you can keep track of correct answers and provide a scoreboard.

Then you can build on that idea. You can add multiplayer support. A timer to answer the questions. Some fun animations, etc. Just add onto it piece by piece until you have something.

# Play Ball
I'm not particularly fond of Baseball. I played Little League as a kid, I umpired games for the **really** small kids, and I played in High School. But I sort of lost interest in it after that.

I decided to do this project because I had given this project to people that I had mentored in the past and I wanted to see how difficult it really was, (maybe I was asking too much of them). Now, I didn't build a Baseball game with full 3D graphics and controller support. It's basically just a bunch of HTML output in the browser:

![A baseball scoreboard with Away Team and Home team, outs, strikes, balls, who is at bat, and runners on base](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ro0xnc7dp9ycq3rxzn7q.png)

I've abstracted away a lot of the complexity. You don't swing at a pitch or anything. You just pitch the ball. Then a random number generator will either make that pitch a "strike", or a "ball". Once you get to 4 balls the batter is "walked". If you get 3 "strikes" the batter is out. Basically I just use the fundamental rules of baseball to keep track of everything.

![A code file showing a switch statement](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ilxlidn6mqnind98t4qd.png)


I picked baseball because it's a relatively slow paced game but you can really do this with anything:
- Horse Racing
- Tennis
- A simple solar system simulator
- Cricket
- A (Pet) Program where there is a creature of some sort that you have to take care of.

There are tons of options. Pick something you enjoy and simulate it. Start small, and build the project up. Do you think that Twitter or Dev.to started out the way they are now? Nope. Twitter probably had the ability to login and send a message and that was it. You probably couldn't like, follow, retweet, block, mute, etc. They built an app with minimal functionality and build up from there.

Here is the link to my [easy-baseball](https://github.com/denvercoder/easy-baseball) repo if you'd like to take a look at the whole project. You can run it yourself and try and figure out how it works. It's actually not a lot of code so don't be intimidated. Just go have a look. 

If you want you have my full permission and encouragement to build on this project. There isn't a lot of functionality and there are a few bugs. See if you can find them and fix them.

Thanks for reading and that's all y'all.