I know all you guys need to make games, amazing websites... and more.recommended for @Bookie0So let's start!
A hello world example can be writed with 3 examples:
console.log("Hello World!"); // or Console.log("Hello World!");
And then you just click inspect in the document and hit console and you should see:
Hello World!
document.write("Hello World!"); // or Document.write("Hello World!");
And then you should see in your document "Hello World!" in the left top of your document.
alert("Hello World!");
And then you should see an alert comes says "Hello World!"
Variables are so simple in javascript(let's call it js)...you must write:
var a_string = "Hello World!";
and then you can write:
var a_string = "Hello World!"; // and then console.log(a_string); // or document.write(a_string); // or alert(a_string);
Very simple!
If statements in js are so helpful!
you can write:
var name = "Zuhdi"; if(name === "Zuhdi"){ alert("Hello Zuhdi!"); } else { alert("I don't know you."); }
and then it will come an alert says "Hello Zuhdi" because name is equal to Zuhdi!
name
Zuhdi
I don't need to late on comments...you only should write:
// this is a comment
Functions are soooooo cooool in js!
function add(num1, num2){ var result = num1 + num2; return result; }
then you shoudl CALL the function:
add(5, 17);
and the output will be 22
22
because in the add function we put in these () a num1 and num2... and when we call it, we wrote in the () our numbers
()
THAT'S IT!
From what we learned today: we need to make a simple calc!
let's start:
var num1 = prompt("First number:") var num2 = prompt("Second number:") var op = prompt("Operator:") num1; num2; op; if(op === "+"){ alert(num1 + num2); } else if(op === "-"){ alert(num1 - num2); } else if(op === "/"){ alert(num1 / num2) } else if(op === "*"){ alert(num1 * num2); } else { alert("INVALID!") }
try this code and see the output!
@Baconman321 Thank you so much for the suggesting!
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!
@Baconman321 Thank you so much for the suggesting!