I’ve tried and failed to learn to program many times in my life.
I’ve spent thousands of dollars and hundreds of hours.
Enough is enough.
Now that I’m focused on privacy and OSINT, it’s time for me to really learn to program.
I have lots of ideas for tools to make my job easier.
Here I am learning Javascript.
I will also be focusing on learning Python in the future.
Right now I’m focused on Javascript.
The first thing everyone always learns is “Hello World.”
But I found three ways to write Hello World in Javascript.
I’m sure there are at least 100 more ways, but these three seem to be the three most important places to start.
All three will be used heavily throughout our lives programming.
If you’re brand new to programming, they’re called functions.
In JavaScript, we always end with a semicolon ;
.
First, we start with console.log()
.
console.log("Hello World!");
The function console.log()
is important because we will use it a lot for testing.
Having a message display in the console doesn’t modify the page at all.
We can have it return information to confirm our code works as intended, or return errors if it doesn’t.
Sometimes pieces of our code won’t have any other way of clearly displaying whether it’s working as intended or not.
We use console.log()
to return messages with information in the browser console.
Just type console.log()
and then, in between the parenthesis, add your message in quotes ""
.
Don’t forget your semicolon ;
at the end.
console.log("Hello World!");
Play with it on Codepen (click the “Edit on Codepen” and then delete the //
before the console.log()
line):
See the Pen js hello world by Garrett (@quadiumstaral) on CodePen.
I don't have anything free to bribe you with.
Next we move on to alert()
.
alert("Hello World!");
While we use console.log()
to notify us, the programmer, of errors, alert()
is one thing we can use to notify the user of an error.
The alert()
function creates a small popup window with brief message.
Just like with console.log()
, add your message in quotes ""
between the parenthesis of alert()
.
And again, don’t forget your semicolon ;
at the end.
alert("Hello World!");
Play with it on Codepen (click the “Edit on Codepen” and then delete the //
before the alert()
line):
See the Pen js hello world by Garrett (@quadiumstaral) on CodePen.
We close this lesson with document.write()
.
document.write("Hello World!");
The function document.write()
is just one of the many ways to modify a web page with JavaScript.
It’s just as easy as console.log()
and alert()
, but it will make a visible change to the web page we are viewing.
Just like with console.log()
and alert()
, add your message in quotes ""
between the parenthesis of document.write()
.
I keep repeating this because it’s a common problem people have: don’t forget to end with a semicolon ;
.
document.write("Hello World!");
Play with it on Codepen (click the “Edit on Codepen” and then delete the //
before the document.write()
line):
See the Pen js hello world by Garrett (@quadiumstaral) on CodePen.
This has been pretty boring so far.
This is only the first post.
The first thing we’ve learned.
It will get better.
I’ll kick it up a notch for the next post.
Photo by Greg Rakozy on Unsplash
Garrett Mickley
I've been working in digital marketing for a decade and a half, and I'm ready for a career change. This blog is my journal.I don't have anything free to bribe you with.