forked from Grow-with-Open-Source/Javascript-Projects
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscrip.js
More file actions
56 lines (50 loc) · 1.83 KB
/
scrip.js
File metadata and controls
56 lines (50 loc) · 1.83 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
function count() {
var ini = window.document.getElementById('txtinicio')
var fim = window.document.getElementById('txtfim')
var passo = window.document.getElementById('txtpasso')
var res = document.querySelector('p#conta')
var i = Number(ini.value)
var f = Number(fim.value)
var p = Number(passo.value)
if(ini.value.length == 0 || fim.value.length == 0 || passo.value.length == 0) {
window.alert('Fill in the start, end and step fields correctly')
res.innerHTML = 'Impossible to count'
} else if (p == 0 || p < 0) {
window.alert('Incorrect step, the program will assume the value 1')
res.innerHTML = `Counting: <br>`
p = 1
if (i < f) {
// Upward count with incorrect step
while (i <= f) {
res.innerHTML += `\u{1F449} ${i}`
i += p
}
res.innerHTML += `\u{1F449}`
res.innerHTML += '\u{1F3C1}'
} else {
// Countdown with incorrect step
while (i >= f) {
res.innerHTML += `\u{1F449} ${i}`
i -= p
}
res.innerHTML += `\u{1F449}`
res.innerHTML += '\u{1F3C1}'
}
} else if (i < f) {
// Count up
res.innerHTML = `Counting: <br> `
while (i <= f) {
res.innerHTML += `\u{1F449} ${i}`
i += p
}
res.innerHTML += `\u{1F449} `
res.innerHTML += '\u{1F3C1}'
} else {
// Countdown
res.innerHTML = `Counting: <br>`
while (i >= f) {
res.innerHTML += `\u{1F449} ${i}`
i -= p
}
}
}