SOW - Session #4 - Javascript
SOW - Session #4 - Javascript
Session #4
Recap - JS continue
24/02/2024
Merhba
&
Welcome Back
Outline
I. Recap - HTML & CSS
II. JS - Intro
III. JS - In Depth
01. Recap
Recap
Recap
- CSS allows you to create rules that specify how the content of an element should appear.
Recap
Recap
http://preinscription.uca.ma
CSS - Syntax
CSS Syntax
Link
CSS - Selectors
CSS Selectors
Id Selector
- Select the HTML element that has the specified Id
- Id is unique within the page
<p>Hello World</p>
<section class=”centered”>Hello from the other side
</section>
<p class=”centered”>Hello, It’s me</p>
.centered {
text-align: center;
<p>Hello World</p> color: red;
<section class=”centered”>Hello from the other side
</section> }
<p class=”centered”>Hello, It’s me</p>
CSS Selectors
Grouping Selector
- Select All HTML elements within a page with specific tag names.
<p>Hello World</p>
<section class=”centered”>Hello from the other side
</section>
<p class=”centered”>Hello, It’s me</p>
<h6>Hello, How are you ?</h6>
p, h6 {
<p>Hello World</p>
text-align: center;
<section class=”centered”>Hello from the other side color: red;
</section> }
<p class=”centered”>Hello, It’s me</p>
<h6>Hello, How are you ?</h6>
CSS - Where To
CSS Where To
- You can apply CSS in 3 ways :
- Inline style
- It enables you to create dynamically updating content, control multimedia, animate images.
<html>
<head> <html>
<title>My title</title> <head>
</head> <title>My title</title>
<body> </head>
<h1 id="head1" onclick='myfunction()'>A <body>
heading</h1> <h1 id="head1"
... onclick='myfunction()'>A
<script> heading</h1>
function myFunction() { <a class=’cls1’ href='#'>Link
document.getElementById("head1").innerHTML = "A text</a>
changes Heading 1";}
<p>Hakuna Matata</p>
</script>
</body>
</body>
</html> </html>
JS Where To
- Using the attribute src of the script tag
<head>
<script src="./script.js" /> <html>
</head> <head>
<body> <title>My title</title>
... </head>
<body>
<script src="./script.js" />
<h1 id="head1"
</body>
onclick='myfunction()'>A
heading</h1>
// script.js <a class=’cls1’ href='#'>Link
function myFunction() { text</a>
document.getElementById("head1").innerHTML = "A <p>Hakuna Matata</p>
changes Heading 1"; </body>
} </html>
JS - Events
JS Events
- HTML events are actions that happen to HTML elements. ( Firing, Triggering )
<body>
<h1 onclick='myfunction()'>A heading</h1>
<a class=’cls1’ href='#'>Link text</a>
<p>Hakuna Matata</p>
</body>
Event : is the click event Handler : myfunction()
// script.js
function myFunction() {
document.getElementById("head1").innerHTML = "A
changed Heading 1";
}
JS Events
03. JSS
JS
pages.
- It enables you to create dynamically updating content, control multimedia, animate images.
if (formatted) {
}
JS - Statements
if (formatted) {
- Although the semicolon (;) is optional; you should always use it to terminate a statement.
JS - Comments
// this is a single-line comment
- Comments are very useful when writing code, they allow you to include notes or hints.
- When executing the code, the JavaScript engine ignores the comments.
JS - Identifiers
- An identifier is a name you choose for variables, parameters, functions, classes, etc.
if (formatted) {
}
JS - Identifiers
- Can Start with a letter (a-z, or A-Z), an underscore(_), or a dollar sign ($).
- Can contain a sequence of characters including (a-z, A-Z), numbers (0-9), underscores (_), and
myVar1 yes
List oranges22 no
$username yes
0password no
Bonus
JS - Reserved keywords
JS - Variables
JS - Variables
- A variable is a label that references a value like a number or string. Before using a variable,
var message;
let formatted;
JS - Variables
- A variable is a label that references a value like a number or string. Before using a variable,
variable.
variable.
message = 100;
JS - Operators
message = 100;
Give it a try
- Arithmetic Operators ( + - / *)
- Assignment operators ( = += -= *= )
x = x + 1;
y+= 1;
console.log(x);
console.log(y);
console.log(x++);
console.log(++y);
console.log(x);
console.log(message + user);
JS - Conditions
JS - Conditions
if( condition )
statement;
if( condition ) {
// ...
} else {
// ...
}
while (expression) {
// statement
}
let count = 1;
while (count < 10) {
console.log(count);
count +=2;
}
JS - Conditions
do {
statement;
} while(expression)
let count = 0;
do {
console.log(count);
count++;
} while (count < 5)
JS - Conditions
for ( ; ; ) {
// statements
}
- It enables you to create dynamically updating content, control multimedia, animate images.
- It enables you to create dynamically updating content, control multimedia, animate images.
- It enables you to create dynamically updating content, control multimedia, animate images.
- It enables you to create dynamically updating content, control multimedia, animate images.
- It enables you to create dynamically updating content, control multimedia, animate images.
- It enables you to create dynamically updating content, control multimedia, animate images.
- It enables you to create dynamically updating content, control multimedia, animate images.