Friday, July 26, 2013

The New Blackjack App!

If you like Blackjack, you'll like the app I just spent the past maybe week or so working on. I randomly had the idea to start creating an app where you can play a basic game of Blackjack (sometimes called 21) versus the dealer.

The app is JavaScript-powered and uses HTML5 for audio and localStorage.

The game features localStorage to store your total amount of money in your browser, money which is taken to games (as if you were bringing real money in the hopes that you would win it in the end). It is also used to store some stats in your browser as well. You make a ten dollar bonus every day for playing, so if you run out of money overall, you have to wait to play another game!

The play the new Blackjack app, go to http://www.themadcomputer.com/games/blackjack.

Monday, May 27, 2013

Arrays in localStorage

Have you ever tried to create an array with a localStorage variable? When you tried to get one of the values in the array, was all you got a single letter?

If so, the best way to solve this is by constructing the array as a regular localStorage variable.

In this example, I'll use localStorage.array. Let's say that this array uses the value "Rick", "Mark", and "Kathy".

localStorage.array=["Rick","Mark","Kathy"];

I want to get localStorage.array[1], which should return "Mark". But when I access "1", it usually will return the value "i" in this case, which is the second letter in the value. So to solve this problem, we'll use the split() method in JavaScript to return the localStorage value as an array. The character to split could be anything, but I'll use "||". Also note that you shouldn't write it as a standard array; write it like it's a non-array variable.

localStorage.array="Rick||Mark||Kathy";

Now, to access what would be "Mark", we'd simply insert this wherever we want the value used:

localStorage.array.split("||")[1]

So, again, in order to return a localStorage variable as an array, you must first choose a/some character(s) to split the array values. Then write the variable normally and use that/those character(s) that you specified. When you want to access a certain value, use the split() function and the number.

Sunday, May 26, 2013

What's Happening at the Moment

I have been lacking posting and working on programming lately. I apologize for this long period of silence.

I haven't been doing much work on my CSS tutorial at all and I'm afraid that I have to say I won't be continuing working on the tutorial or the JavaScript one. I don't know about the Web tutorial either.

However, I'm still keeping my HTML tutorial (and the site!) up and running and am also thinking of more ideas for my website.

I will also think up new tips to post here on the blog.

If you were waiting for my CSS tutorial (or any other ones), I apologize. The best place to go learn these subjects is at www.w3schools.com, one of the most popular developer sites out there. You can learn a ton of programming languages there.

I apologize again. CSS and JavaScript have a heck of a lot to cover. I know that I could do it, but it's not working out.

I'll be back soon!

Tuesday, May 14, 2013

What's Going On?

I apologize for my lack of posting. This is just a quick post to let you know how the progress of my CSS tutorial is going.

It's so far been a slow progress, but I have been working on it now and then. I should soon be back to working on that section of my website, and then will start working on the JavaScript tutorial.

Also, if you don't know already, I released my HTML tutorial on my website, www.themadcomputer.com. If you want to learn HTML, go to www.themadcomputer.com/html_tutorial.php. My website will eventually be a place to learn HTML, CSS, JavaScript, and Web stuff (like publishing your website online).

Tuesday, April 2, 2013

The Tracking Code Solution

You may already know this: When using a website visitor counter (like StatCounter, Google Analytics, etc.), and are editing the raw code on your website, a snippet of JavaScript is typically required.

But it can be a nightmare if you install the tracking code manually on every page. What happens if you have to reinstall the tracking code for some reason, and you have to go back to every page and install it? That would take a while.

The answer here is a PHP "include" function and a file with the script code. Make a little .php file that contains only the JavaScript snippet, and nothing else. Then use a code like <?php include 'filename.php' ?> to access the file (replace filename with the name of the tracking code file). Insert this code inside every page, so if for some reason you have to reinstall your JavaScript code, you can insert the JavaScript code into the .php file.

Something to note: PHP does not allow you to include a file that is in a directory different from the one with the file containing the "include" function. In short, you can't including files from other site "folders" (directories).

I hope this code tip helps. If you would like to be regularly emailed with things like my latest blog post, quick code tips, and other information, subscribe to my newsletter.

Saturday, March 23, 2013

The problem of embedding audio and video to a webpage... and the solution

When it comes down to adding any audio or video file to a webpage so a user can play it, there's a problem.

Basically, different browsers support different audio/video types. Some browsers support one audio/video type while other browsers don't support it. Some browsers support a tag for audio/video while others don't.

So how is this solved?

The most basic solution is to use an HTML5 tag with <source> tags and then an <embed> tag, which plays the file if the browser is older and doesn't support HTML5.

This is the code for audio. All italic is where the user-defined code goes.

<audio attributes>
<source type="audio/mp3" src="filename.mp3" />
<source type="audio/ogg" src="filename.ogg" />
<source type="audio/wav" src="filename.wav" />
<embed src="filename.mp3/other" />
</audio>

The code for video is similar:

<video attributes>
<source type="video/mp4" src="filename.mp4" />
<source type="video/ogg" src="filename.ogg" />
<source type="video/webm" src="filename.webm" />
<embed src="filename.mp4/other" />
</video>

You may want to make multiple copies of the file. Each file will be a different file type. Then you can create how ever many <source> tags are needed, and pick the best one to use for the <embed> tag.

While this solution is a good one, it still has a couple flaws. For example, you cannot provide a fallback for the <embed> element. Another one is that if the <embed> fallback is used in no-HTML5-support browsers, the browser may still be missing something like a plugin to play the file.

I recommend that you find something (like YouTube) that allows you to embed media on a website, cross-browser.

Saturday, March 16, 2013

The new TheMadComputer.com has been officially released!

TheMadComputer.com is officially a place for learning how to create a website from scratch. The HTML tutorial, plus the new features, have all been released, as I said they would be.

If you want to create a website from scratch but don't know how, HTML is the first thing you'll want to learn. Go to www.themadcomputer.com/html_tutorial.php and start learning HTML today!

The new website version also allows you to subscribe to my newsletter. I plan on sending it out every Saturday, or at least once a week. The newsletter will contain code tips, my latest blog post, and more. Go subscribe at www.themadcomputer.com/subscribe.

A convenient search bar, accessible on nearly every page, lets you find what you need. Whether you are studying a programming language or know that language but don't remember something, the search bar lets you find it quickly.

Finally, the games and apps that were included with my old themadcomputer.com version are still available, at www.themadcomputer.com/extras.