-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTEMA2_P2.html
More file actions
41 lines (33 loc) · 1.18 KB
/
TEMA2_P2.html
File metadata and controls
41 lines (33 loc) · 1.18 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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Inversare litere</title>
</head>
<body>
<h2>Transformă literele în opusul lor din alfabet</h2>
<label>Introdu un cuvânt:</label>
<input type="text" id="cuvantUtilizator"><br><br>
<button onclick="inverseazaLitere()">Inversează</button>
<p id="rezultatText"></p>
<script>
function inverseazaLitere() {
let cuvant = document.getElementById("cuvantUtilizator").value;
cuvant = cuvant.toLowerCase(); // toate literele mici
let rezultatFinal = "";
for (let i = 0; i < cuvant.length; i++) {
let litera = cuvant[i];
let codLitera = litera.charCodeAt(0);
if (litera >= 'a' && litera <= 'z') {
let codNou = 122 - (codLitera - 97); // 97 = 'a', 122 = 'z'
let literaNoua = String.fromCharCode(codNou);
rezultatFinal = rezultatFinal + literaNoua;
} else {
rezultatFinal = rezultatFinal + litera; // dacă nu e literă (spațiu, semn), o las așa
}
}
document.getElementById("rezultatText").innerText = "Rezultatul este: " + rezultatFinal;
}
</script>
</body>
</html>