You just found the differences between these two files by hand and
it worked all right.
But it probably seemed pretty tedious and the files were also small.
What if you had files with hundreds or even thousands of lines?
Let's take a look at what we could do in that case.
Now, let's take a look at a program that require's a bit more code.
This is a game called Asteroids and I know this text is a little hard to read,
but it says press space to start.
Some of you may recognize that this is a classic arcade game that has been
ported so you can play it in the browser.
You press the left and
right arrow keys to turn the ship, up to fire the engine, and space to shoot.
Props to Doug McGuiness for creating this game.
If you want to play it yourself,
there's a link to it on Doug's website in the instructor notes.
But right now, we're going to be focusing on finding a bug in its code.
The code for this game is in JavaScript.
But don't worry, you won't need to know JavaScript to complete the exercise.
I thought using space to fire the engine might be more intuitive to me, so
I changed the controls for the game to use space instead of up arrow.
Then I needed a different way to shoot, so
I decided to use enter instead of space for that.
But when I tried the game out,
the engines didn't work at all anymore, I couldn't move.
I think I made a typo, but I'm not sure where.
Most of the code for this game,
including the codes that maps keys to actions, is in a file called game.js.
Now, this file contains over a thousand lines.
It would be way too time consuming to go through this entire file,
comparing the new version to the old version.
Fortunately, there are a bunch of tools that can automatically find
differences between files.
If you're using Windows,
you have a tool in the command prompt called FC, which stands for file compare.
If you're using Mac or Linux, then FC is a different unrelated command, but
you have a built-in tool, called Diff, you can use, which stands for difference.
I'll demonstrate using these tools to compare the HTML you
just compared manually in the previous exercise.
Then I'll ask you to go through the same process to
find the differences in game.js.
On Windows, I'll open the command prompt first.
By the way, if you'd prefer to use git bash to complete this exercise, then,
you can follow the instructions for the Mac and
Linux students that are coming in a minute.
But for now,
I'm going to show how to complete the exercise in the command prompt.
So first, I'll need to change to the directory that has my files in it.
So I'll type cd Downloads.
Since I downloaded my files to the downloads folder.
Now I'll enter the command FC favorite-app-old.html favorite-app.html.
So, to the FC or File Compare Program, I passed two files,
the first one that I want to compare, and the second.
Now, when I hit enter, I can see that
I'm comparing the files Favorite-app-old.html and FAVORITE-APP.HTML.
So, each of these two sections are showing different parts of the file.
So here, you can see that favorite-app-old.html href style-1.css, and
FAVORITE-AP.HTML href style-!.css.
Then down here, you can see the next section that changed,
which was the description.
Some description here changed to the fun fact.
Did you know that sunflowers were used to remove toxins from
a pond after the Chernobyl disaster?
Sections that didn't change aren't shown,
since we're only trying to focus on the differences here.
On Mac or Linux, I'll open the terminal, navigate to where the files are,
then enter the command diff -u favorite-app-old.html favorite-app.html.
The -u option stands for
unified diff format and it will make the output a little easier to read.
Now, I'll go ahead and hit Enter.
The output format here is a little bit different than for FC.
I'll scroll back up.
And first, you can see that there were some lines at the top.
And you don't really need to worry about these lines.
They're just showing you that you're comparing favorite-app-old.html,
to favorite-app.html.
Ones with no plus or minus sign next to them like these haven't changed.
That is they existed in both the old version of the file and the new version.
Lines with a minus sign were removed.
That is they existed in the old version, but not the new version.
And lines with a plus sign were added, so vice versa.
Now I'll scroll back down.
And here's the style sheet change that you found earlier.
And here's the description change.
Now, go ahead and download the filesgameold.js and gamenew.js from
the downloadable section and compare them using either FC or Diff.
Your files will probably be downloaded to the downloads folder, so
you can navigate there by using CD downloads, just like I did.
What word contains a typo in the version of game.js but not in the old version?
Once you found the word, enter it in this box.
Use the correct spelling for the word.