0001 created[index.js, style.css, index.html, javascript.txt], added [7 Chapters]
This commit is contained in:
0
css/style.css
Normal file
0
css/style.css
Normal file
11
documentation/javascript.txt
Normal file
11
documentation/javascript.txt
Normal file
@@ -0,0 +1,11 @@
|
||||
Sources: Youtube: Bro Code https://www.youtube.com/watch?v=8dWL3wF_OMw
|
||||
|
||||
Javascript is a webbased programming language which is used to:
|
||||
-> add interactive behavior to webpages
|
||||
-> build web and mobile applications
|
||||
-> create command line tools
|
||||
-> develop games
|
||||
|
||||
Used web browser: Firefox
|
||||
Used text editor: VSCode
|
||||
|
||||
16
html/index.html
Normal file
16
html/index.html
Normal file
@@ -0,0 +1,16 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Document</title>
|
||||
<link rel="stylesheet" href="/css/style.css">
|
||||
</head>
|
||||
<body>
|
||||
<p id="p1"></p>
|
||||
<p id="p2"></p>
|
||||
<p id="p3"></p>
|
||||
<script src="/js/index.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
114
js/index.js
Normal file
114
js/index.js
Normal file
@@ -0,0 +1,114 @@
|
||||
//1. Comments
|
||||
//This is a comment. Comments are used to make others understand your code.
|
||||
/*
|
||||
This
|
||||
is
|
||||
a
|
||||
multiline
|
||||
comment
|
||||
*/
|
||||
//--------------------------------------------------------------------------------------------------------------
|
||||
|
||||
//2. Console messages
|
||||
//Print message to console. Open console at webbrowser(Firefox) via Ctrl+Shift+I and go to tab "Console"
|
||||
console.log("I can't eat pizza! :(");
|
||||
console.log("I know it's really good.");
|
||||
//--------------------------------------------------------------------------------------------------------------
|
||||
|
||||
//3. Allerts
|
||||
//Show allert at browser-window.
|
||||
//window.alert("I REALLY WOULD LOVE TO EAT PIZZA!");
|
||||
//--------------------------------------------------------------------------------------------------------------
|
||||
|
||||
//4. Variables (and constants)
|
||||
//A variable is a container for storing simple data as numbers, sentences, letters, etc.
|
||||
//A variable behaves as if it was the value that it contains.
|
||||
|
||||
//a) Declaration (var, let, const)
|
||||
//b) Assignment(Definition) (= assignment-operator)
|
||||
|
||||
//To use let is best in terms of good programming behavior because variables declared with
|
||||
//let can only be declared once at their scope, wjich means that we will get an error if we
|
||||
//don't care about that rule.
|
||||
|
||||
//a)
|
||||
let age;
|
||||
console.log(age); //value of age is undefined, since we didn't assign any value to it.
|
||||
//b)
|
||||
age = 99; //age is now a variable from type "number".
|
||||
console.log(age);
|
||||
|
||||
//a) + b)
|
||||
let firstName = "WickedJack99"; //firstName is now a variable from type "string".
|
||||
console.log(firstName);
|
||||
|
||||
//a) + b)
|
||||
let student = true; //student is now a variable from type "boolean".
|
||||
console.log(student);
|
||||
|
||||
//a) + b)
|
||||
let age2 = "99";
|
||||
|
||||
//4.1 Differences between numbers and strings.
|
||||
age = age + 1;
|
||||
age2 = age2 + 1;
|
||||
console.log(age);
|
||||
console.log(age2);
|
||||
//--------------------------------------------------------------------------------------------------------------
|
||||
|
||||
//5. Printing multiple strings together to console
|
||||
//Using , instead of + automatically prints a whitespace behind the string.
|
||||
//Using + to concatinate, doesn't print a whitespace behind the string.
|
||||
console.log("Hello", firstName, "You are", age, "years old.");
|
||||
console.log("Hello" + firstName + "You are" + age + "years old.");
|
||||
//--------------------------------------------------------------------------------------------------------------
|
||||
|
||||
//6. Change text of html-element
|
||||
document.getElementById("p1").innerHTML = "Hello " + firstName;
|
||||
document.getElementById("p2").innerHTML = "You are " + age + " years old.";
|
||||
document.getElementById("p3").innerHTML = "Enrolled: " + student;
|
||||
//--------------------------------------------------------------------------------------------------------------
|
||||
|
||||
//7.Arithmetic expressions
|
||||
let students = 20;
|
||||
|
||||
//7.1 Addition
|
||||
students = students + 1;
|
||||
students++;
|
||||
students += 2;
|
||||
console.log(students);
|
||||
|
||||
//7.2 Subtraction
|
||||
students = students - 1;
|
||||
students--;
|
||||
students -= 2;
|
||||
console.log(students);
|
||||
|
||||
//7.3 Multiplication
|
||||
students = students * 2;
|
||||
students *= 2;
|
||||
console.log(students);
|
||||
|
||||
//7.4 Division
|
||||
students = students / 4;
|
||||
students /= 4;
|
||||
console.log(students);
|
||||
|
||||
//7.5 Modulus (Remainder of division)
|
||||
students = students % 3;
|
||||
students %= 3;
|
||||
console.log(students);
|
||||
|
||||
//7.5.1 If number is even, number % 2 = 0
|
||||
//7.5.2 If number is uneven, number % 2 != 0
|
||||
|
||||
/* Operator pecedence
|
||||
1. Paranthesis ()
|
||||
2. Exponents ^2
|
||||
3. Multiplication and Division
|
||||
4. Addition and Subtraction
|
||||
*/
|
||||
//--------------------------------------------------------------------------------------------------------------
|
||||
|
||||
//8. Accept user input
|
||||
//https://youtu.be/8dWL3wF_OMw?t=1288
|
||||
Reference in New Issue
Block a user