forked from thejsway/thejsway_fr-code
-
Notifications
You must be signed in to change notification settings - Fork 0
/
chapitre8_exercice2.js
44 lines (41 loc) · 955 Bytes
/
chapitre8_exercice2.js
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
// Leet Speak
// Renvoie l'équivalent "leet speak" d'une lettre
function convertirLettreLeet(lettre) {
// Par défaut, la lettre ne change pas
let lettreLeet = lettre;
switch (lettre.toLowerCase()) {
case "a":
lettreLeet = "4";
break;
case "b":
lettreLeet = "8";
break;
case "e":
lettreLeet = "3";
break;
case "l":
lettreLeet = "1";
break;
case "o":
lettreLeet = "0";
break;
case "s":
lettreLeet = "5";
break;
case "t":
lettreLeet = "7";
break;
}
return lettreLeet;
}
// Renvoie un mot converti en "leet speak"
function convertirMotLeet(mot) {
let motLeet = "";
for (const lettre of mot) {
motLeet += convertirLettreLeet(lettre);
}
return motLeet;
}
console.log(convertirMotLeet("Hello World!")); // "H3110 W0r1d!"
console.log(convertirMotLeet("Noob")); // "N008"
console.log(convertirMotLeet("Hacker")); // "H4ck3r"