-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjavascript.html
More file actions
112 lines (70 loc) · 3.27 KB
/
javascript.html
File metadata and controls
112 lines (70 loc) · 3.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h1>JavaScript (JS) is a lightweight, interpreted, or just-in-time compiled programming language with first-class functions.<br> While it is most well-known as the scripting language for Web pages, many non-browser environments also use it, such as Node.js, Apache CouchDB and Adobe Acrobat.<br> JavaScript is a prototype-based, multi-paradigm, single-threaded, dynamic language, supporting object-oriented, imperative, and declarative (e.g. functional programming) styles.</h1>
<hr>
<h1>
A FEW COMMANDS TO INTERACT WITH THE USER:</h1>
<h2>Alert<h2> <br>
*alert("Hello");
The mini-window with the message is called a modal window.<br>
The word “modal” means that the visitor can’t interact with<br>
the rest of the page, press other buttons, etc, until they have dealt with the window.<br>
In this case – until they press “OK”.*<br>
<hr>
<h2> prompt</h2><br>
*The function prompt accepts two arguments:<br>
result = prompt(title, [default]);<br>
It shows a modal window with a text message, an input field for the visitor, and the buttons OK/Cancel.*<br>
<h2>Confirm<h2>
*shows a message and waits for the user to press “OK” or “Cancel”. It returns true for OK and false for Cancel/Esc.
All these methods are modal: they pause script execution and don’t allow the visitor to interact with the rest of the page until the window has been dismissed.*
<hr>
<h1>
Conditional Branching
</h1>
<vr>
>Sometimes, we need to perform different actions based on different conditions.
>To do that, we can use the if statement and the conditional operator ?, that’s also called a “question mark” operator.
<h1>The “if” statement</h1>
>The if(...) statement evaluates a condition in parentheses and, if the result is <br>
true, executes a block of code.<br>
<vr>
>>>For example:<br>
let year = prompt('In which year was ECMAScript-2015 specification <br>
published?', '');<br>
if (year == 2015) alert( 'You are right!' );<br>
In the example above, the condition is a simple equality check > <br>
(year == 2015), but it can be much more complex.<br>
>>>if we want to execute more than one statement, we have to wrap our code block inside curly braces:<br>
(year == 2015) {<br>
alert( "That's correct!" );<br>
alert( "You're so smart!");<br>
<hr>
<h1>
The "else" Clause
</h1>
>The “else” clause<br>
The if statement may contain an optional “else” block. It executes when the condition is falsy.<br>
For example:<br>
let year = prompt('In which year was the ECMAScript-2015 specification published?', '');<br>
if (year == 2015) {<br>
alert( 'You guessed it right!' );<br>
} else {<br>
alert( 'How can you be so wrong?' ); // any value except 2015<br>
}
<h1>several conditions: “else if”</h1>
>Sometimes, we’d like to test several variants of a condition. The else if clause lets us do that.<br>
For example:
let year = prompt('In which year was the ECMAScript-2015 specification published?', '');<br>
if (year < 2015) {<br>
alert( 'Too early...' );<br>
} else if (year > 2015) {<br>
alert( 'Too late' );<br>
} else {<br>
alert( 'Exactly!' );<br>
}
</body>
</html>