HTML Diff
0 added 0 removed
Original 2026-01-01
Modified 2026-03-09
1 <h2>How to include several scripts on a page</h2>
1 <h2>How to include several scripts on a page</h2>
2 <p>In order to include yet another file with JavaScript code on a page, use the script tag again:</p>
2 <p>In order to include yet another file with JavaScript code on a page, use the script tag again:</p>
3 &lt;body&gt; &lt;script src="themes.js"&gt;&lt;/script&gt; &lt;script src="likes.js"&gt;&lt;/script&gt; &lt;/body&gt;<p>The browser processes the instructions sequentially: first in the first file, then in the second, as though they were located in a single place. Applications are often divided into several files, where usually one task corresponds to one file: for example, managing themes or subscribing to a newsletter.</p>
3 &lt;body&gt; &lt;script src="themes.js"&gt;&lt;/script&gt; &lt;script src="likes.js"&gt;&lt;/script&gt; &lt;/body&gt;<p>The browser processes the instructions sequentially: first in the first file, then in the second, as though they were located in a single place. Applications are often divided into several files, where usually one task corresponds to one file: for example, managing themes or subscribing to a newsletter.</p>
4 <h2>Numbers</h2>
4 <h2>Numbers</h2>
5 <p>A variable can be assigned a value. Numbers do not need to be enclosed in quotation marks:</p>
5 <p>A variable can be assigned a value. Numbers do not need to be enclosed in quotation marks:</p>
6 let number = 0;<p>To increase or decrease the number in JavaScript, you can use various entries:</p>
6 let number = 0;<p>To increase or decrease the number in JavaScript, you can use various entries:</p>
7 // Fully entry number = number + 2; // Variable value: 2 number = number - 2; // Variable value: 0 // Short entry number += 2; // Variable value: 2 number -= 2; // Variable value: 0 // Increase the number by 1 number++; // Variable value: 1 // Decrease the number by 1 number--; // Variable value: 0<h2>classList.contains method</h2>
7 // Fully entry number = number + 2; // Variable value: 2 number = number - 2; // Variable value: 0 // Short entry number += 2; // Variable value: 2 number -= 2; // Variable value: 0 // Increase the number by 1 number++; // Variable value: 1 // Decrease the number by 1 number--; // Variable value: 0<h2>classList.contains method</h2>
8 <p>The classList.contains method checks if an element has a class:</p>
8 <p>The classList.contains method checks if an element has a class:</p>
9 element.classList.contains('class');<p>The method will return true if the element has a class, and false if there is no class. The true and false values are called boolean values. There are only two such values.</p>
9 element.classList.contains('class');<p>The method will return true if the element has a class, and false if there is no class. The true and false values are called boolean values. There are only two such values.</p>
10 <h2>Conditional statement</h2>
10 <h2>Conditional statement</h2>
11 <p>A conditional statement allows you to perform actions depending on a <i>condition</i>. A condition is an instruction that returns true or false. A conditional statement looks like the following:</p>
11 <p>A conditional statement allows you to perform actions depending on a <i>condition</i>. A condition is an instruction that returns true or false. A conditional statement looks like the following:</p>
12 if (condition) { // Instructions that are executed if the condition is true } else { // Instructions that are executed if the condition is false }<h3>if</h3>
12 if (condition) { // Instructions that are executed if the condition is true } else { // Instructions that are executed if the condition is false }<h3>if</h3>
13 <p>The condition is written in <i>parentheses</i>after the word if. After that, instructions that will be executed if the condition is <i>true</i>are written inside the<i>curly braces</i>. A condition is considered true if the statement inside the parentheses returns true.</p>
13 <p>The condition is written in <i>parentheses</i>after the word if. After that, instructions that will be executed if the condition is <i>true</i>are written inside the<i>curly braces</i>. A condition is considered true if the statement inside the parentheses returns true.</p>
14 <h3>else</h3>
14 <h3>else</h3>
15 <p>The statement else tells JavaScript what to do if the condition is false. Instructions that should be executed if the condition returns false are written inside the curly braces after else.</p>
15 <p>The statement else tells JavaScript what to do if the condition is false. Instructions that should be executed if the condition returns false are written inside the curly braces after else.</p>
16 <p>The use of conditional statements in a script is also called branching, and the code inside the curly braces is called a branch.</p>
16 <p>The use of conditional statements in a script is also called branching, and the code inside the curly braces is called a branch.</p>
17 <h2>append method</h2>
17 <h2>append method</h2>
18 parent-element.append(element to be added);<p>The append method adds the element in parentheses to the end of the parent element. However, the contents of the parent element are not overwritten. You can use this method to add elements and strings of text.</p>
18 parent-element.append(element to be added);<p>The append method adds the element in parentheses to the end of the parent element. However, the contents of the parent element are not overwritten. You can use this method to add elements and strings of text.</p>
19 <h2>createElement method</h2>
19 <h2>createElement method</h2>
20 document.createElement('tag name');<p>To create a new element on the page where the script is included, you need to use the word document. Indicate the element to be created inside the quotation marks in parentheses. For example:</p>
20 document.createElement('tag name');<p>To create a new element on the page where the script is included, you need to use the word document. Indicate the element to be created inside the quotation marks in parentheses. For example:</p>
21 // Create a new element &lt;div&gt; and write it to the variable let newElement = document.createElement ('div');<p>The new element will be accessible from the script, but it will not appear in the markup until we tell JavaScript where to place the new element. To do this, you can use append method:</p>
21 // Create a new element &lt;div&gt; and write it to the variable let newElement = document.createElement ('div');<p>The new element will be accessible from the script, but it will not appear in the markup until we tell JavaScript where to place the new element. To do this, you can use append method:</p>
22 // Find the parent element let parent = document.querySelector('.parent'); // Add a new element to the page parent.append(newElement);<p>Elements that were created using the createElement method can be changed in the same way as any others.</p>
22 // Find the parent element let parent = document.querySelector('.parent'); // Add a new element to the page parent.append(newElement);<p>Elements that were created using the createElement method can be changed in the same way as any others.</p>
23 <h2>Clearing the input field</h2>
23 <h2>Clearing the input field</h2>
24 <p>To prevent the user from mistakenly submitting the form several times, it is better to clear the input field after it is submitted. To do this, write an empty string to its value property. Like this:</p>
24 <p>To prevent the user from mistakenly submitting the form several times, it is better to clear the input field after it is submitted. To do this, write an empty string to its value property. Like this:</p>
25 let input = document.querySelector('input'); input.value = '';<a>Continue</a>
25 let input = document.querySelector('input'); input.value = '';<a>Continue</a>