Repository navigation
Expand file tree
/
Copy pathex27.html
More file actions
82 lines (66 loc) · 2.03 KB
/
Copy pathex27.html
File metadata and controls
82 lines (66 loc) · 2.03 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
<!DOCTYPE html>
<html lang="pt-BR">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Controle de Tentativas com Validação em Duas Etapas (Nome e Idade)</title>
<script src="ex27.js" defer></script>
</head>
<body>
<script>
let counter1 = 0;
let counter2 = 0;
let limit = 3;
function validateLogin(typedName) {
const savedName = "Luan";
if (typedName !== savedName) {
counter1++;
return {
success: false,
message: "Invalid name"
};
} return {
success: true,
message: "Valid name"
};
}
function validateAge(typedAge) {
const savedAge = 30;
if (typedAge !== savedAge) {
counter2++;
return {
success: false,
message: "Invalid age"
};
} return {
success: true,
message: "Valid age"
};
}
while (counter1 < limit) {
const result1 = validateLogin("Luan");
if (result1.success === true) {
console.log(result1.message);
while (counter2 < limit) {
const result2 = validateAge(30);
if (result2.success === true) {
console.log(result2.message);
break;
} else {
console.log("Please try again");
}
}
if (counter2 === limit) {
console.log("Attempt limit exceeded");
}
break;
} else {
console.log("Please try again")
}
}
if (counter1 === limit) {
console.log("Attempt limit exceeded");
}
</script>
</body>
</html>