Skip to content

Commit d1d73af

Browse files
committed
#add final files of the basic course of JS
1 parent 676e6b3 commit d1d73af

File tree

2 files changed

+79
-1
lines changed

2 files changed

+79
-1
lines changed

app.js

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
const heading = document.getElementById('hey')
2+
// const heading2 = document.getElementsByTagName('h2')[0]
3+
// const heading2 = document.getElementsByClassName('h2-class')[0]
4+
// const heading2 = document.querySelector('.h2-class')
5+
const heading2 = document.querySelector('h2') // Всегда возвращает один 1 попавшийся элемент
6+
// console.dir(heading2)
7+
// const heading3 = heading2.nextElementSibling
8+
const h2List = document.querySelectorAll('h2')
9+
// console.log(h2List)
10+
const heading3 = h2List[1]
11+
// console.log(heading3)
12+
13+
14+
// console.log(heading2)
15+
16+
17+
// console.dir(heading.textContent)
18+
19+
setTimeout(() => {
20+
addStylesTo(heading, 'JavaScript')
21+
}, 2000)
22+
23+
setTimeout(() => {
24+
addStylesTo(heading2, 'Is my favorite Programming Language!', 'blue')
25+
}, 3000)
26+
27+
const link = heading3.querySelector('a')
28+
link.addEventListener('click', (event) => {
29+
event.preventDefault()
30+
console.log('Click on link', event.target.getAttribute('href'))
31+
url = event.target.getAttribute('href')
32+
33+
window.location = url
34+
})
35+
setTimeout(() => {
36+
addStylesTo(link, 'And I love it so much :)', 'orange', '3rem')
37+
}, 4000)
38+
39+
function addStylesTo(node, text, color = 'red', fontSize) {
40+
node.textContent = text
41+
node.style.color = color
42+
node.style.textAlign = 'center'
43+
node.style.backgroundColor = 'black'
44+
node.style.padding = '2rem'
45+
node.style.display = 'block'
46+
node.style.width = '100%'
47+
// falsy: '', undefined, null, 0, false
48+
if (fontSize) {
49+
node.style.fontSize = fontSize
50+
}
51+
}
52+
53+
// https://developer.mozilla.org/ru/docs/Web/Events
54+
55+
heading.onclick = () => {
56+
if (heading.style.color === 'red') {
57+
heading.style.color = '#000'
58+
heading.style.backgroundColor = '#fff'
59+
} else {
60+
heading.style.color = 'red'
61+
heading.style.backgroundColor = '#000'
62+
}
63+
}
64+
65+
heading2.addEventListener('click', () => {
66+
if (heading2.style.color === 'blue') {
67+
heading2.style.color = '#000'
68+
heading2.style.backgroundColor = '#fff'
69+
} else {
70+
heading2.style.color = 'blue'
71+
heading2.style.backgroundColor = '#000'
72+
}
73+
})
74+

index.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@
66
</head>
77
<body>
88

9-
<h1>Hello World! I'm armenian king!</h1>
9+
<h1 id="hey" class="heading">Hello World! I'm armenian king!</h1>
10+
11+
<h2 class="h2-class" id="sub-hello">This is heading 2</h2>
12+
13+
<h2><a href="https://developer.mozilla.org/ru/docs/Web/Events" target="_blank">Another h2</a></h2>
1014

1115
<script src="app.js"></script>
1216
</body>

0 commit comments

Comments
 (0)