If you don't have access to an IDE or a website like http://repl.it, you can do all your coding anywhere you are. You need to use a text editor on your computer, like Notepad. There are some things you must do to get started.
First, make a folder on your computer where you can store your files. If you're on a PC, this can be as simple as
right-clicking the desktop and selecting New > Folder
. It's the same basic process if you're using
Google Drive (click New
, then Folder
) or something else like an iMac.
Give the folder a meaningful name, like coding or Room Adventure Game.
Make sure you can see the file extension. By default a text document has .txt
at the end of the file.
You need to be able to change the extensions. You may get a warning not to change them, but it's ok.
Go inside your new folder and create a new text file. Right-click and select New > Text Document
.
You need create a set of three files,index.js
, index.html
and index.css
.
index
? It's so we know they relate to each other.
When you go to a website, you often go to the website's domain. That's the .com
or .edu
type of thing. There are a bunch of them.
Each of those domains load up a default webpage. In most cases, that default webpage is index.html
.
Try this out: Go to a domain you know and at the end add /index.html
and hit enter. This site's domain is http://coding.
.
Go ahead and try this instead: http://coding.
. Go out and try it on other
sites like www.amazon.com
and www.snapchat.com
!
[Note: some sites like google.com
block this]
Now let's do an exercise to test these files out to make sure they work. You're going to edit all three of those
files and then run index.html
.
Open the index.js
file in your text editor. Type in the following line and then save the file.
Open the index.css
file in your text editor. Type in the following line and then save the file.
index.html
file.
There's a basic structure needed for HTML. Without getting into detail here, this code will give you a basic setup for all your webpages.
This code sample is called boilerplate code because you can essentially just start every HTML document
with it. Some programs llet you create a file like this and then every time you start a new project, this would load
automatically, saving you from having to set this structure up each time. This is repl.it's
boilerplate with the <title>
changed.
Some of the code isn't technically required, but it helps make your webpage look correct on different devices and in different browsers.
Notice where it has index.css
and index.js
? If you used other filenames or paths, then
put those names here instead.
Watch your spelling, capitalization, and punctuation throughout.
I used the title The Room Adventure but you can change that to
whatever you want. The <title>
is what shows up in the browser tab or in the title bar.
Go back into the coding
folder you created and double-click the index.html
file.
Your browser should load and give you a popup!
Before you click OK
, you may notice that the browser wait icon may be spinning and that the
background didn't change to lightsteelblue. That's because popups, like the alert take priority in the browser. When you click that OK
button, you'll
see!
One last thing to check. We put a console.log()
command in there. Let's go to the console window to test it out. Open up your
browser's developer tools to get there. Try pressing the F12 key on your keyboard. Then make sure you're in the console
tab. It should say
Test 2.
If all that worked than you're good to go. Leave the index.html
file as it is. But go
back into the index.js
and the index.css
files and delete the few lines in there so you're
not stuck with the blue or the popup.
Only put JavaScript code into the index.js
file.
Only put HTML code into the index.html
file.
Only put CSS code into the index.css
file.
At this point, you're ready to dive into your files and code. You can always add files if you need them, but this will be more than enough for what you need to do.