Even though alert is a global method of window, it is always a good practice to put window in front of alert like this: window.alert('hello world'). The same rule should apply to other built-in methods like prompt, confirm, and more (btw method just means function inside of an object for those who don't know). Also, you forgot to add multi-line comments. Multi-line comments are VERY useful for those who need comments that span multiple lines. This is a better option versus having to put the // on every line of what you are going to say. A multi-line starts like this: / and ends like this /. There are a ton of other languages that support this very commenting syntax. Examples include C++, C, PHP, CSS, and lots more!
[deleted]
@Baconman321 Thank you so much for the suggesting!
@Zuhdi28 Your welcome, great tutorial overall! Oh, and also: Javascript is case sensitive, so I don't know if Document.write would work. Even if it does, you should make sure to present it as document.write not Document.write. Also a quick note, (if you didn't know this) document.write clears everything on the page, meaning if you put a <p> tag in there with text, it would be "deleted".
Hello and welcome to another tutorial!
JavaScript tutorial!
I know all you guys need to make games, amazing websites... and more.
recommended for @Bookie0
So let's start!
1. Hello World!
A hello world example can be writed with 3 examples:
It is very simple... you only should write:
And then you just click inspect in the document and hit console and you should see:
In the first one, we printed hello world in the console...
Now, we will print it in the document!
Like this:
And then you should see in your document "Hello World!" in the left top of your document.
VERY VERY VERY VERY Simple alert in javascript for hello world!
And then you should see an alert comes says "Hello World!"
2. Variables
Variables are so simple in javascript(let's call it js)...
you must write:
and then you can write:
Very simple!
3. If statements
If statements in js are so helpful!
you can write:
and then it will come an alert says "Hello Zuhdi" because
name
is equal toZuhdi
!4. Comments
I don't need to late on comments...
you only should write:
5. Functions
Functions are soooooo cooool in js!
you can write:
then you shoudl CALL the function:
and the output will be
22
Why?
because in the add function we put in these
()
a num1 and num2... and when we call it, we wrote in the()
our numbersSo...
THAT'S IT!
6. Simple Calculator with prompts and alerts.
From what we learned today: we need to make a simple calc!
let's start:
try this code and see the output!
ENJOY!
Even though alert is a global method of window, it is always a good practice to put window in front of alert like this: window.alert('hello world'). The same rule should apply to other built-in methods like prompt, confirm, and more (btw method just means function inside of an object for those who don't know). Also, you forgot to add multi-line comments. Multi-line comments are VERY useful for those who need comments that span multiple lines. This is a better option versus having to put the // on every line of what you are going to say. A multi-line starts like this: / and ends like this /. There are a ton of other languages that support this very commenting syntax. Examples include C++, C, PHP, CSS, and lots more!
@Baconman321 Thank you so much for the suggesting!
@Zuhdi28 Your welcome, great tutorial overall! Oh, and also: Javascript is case sensitive, so I don't know if Document.write would work. Even if it does, you should make sure to present it as document.write not Document.write. Also a quick note, (if you didn't know this) document.write clears everything on the page, meaning if you put a <p> tag in there with text, it would be "deleted".
@Baconman321 thx!
@Zuhdi28 No problem!