這個工程,我想:製作萊特說翻譯
var elite = document.getElementById("elite"),
leet = document.getElementById("leet"),
alphabets = {
a: "4",
b: "8",
e: "3",
g: "6",
i: "1",
o: "0",
p: "9",
s: "5",
t: "7",
z: "2"
},
// words = {
// cool: "kewl",
// dude: "d00d",
// hacker: "h4x0r",
// newbie: "n00b",
// sucks: "sux0r"
// },
words = {
"c00l": "kewl",
"dud3": "d00d",
"h4ck3r": "h4x0r",
"n3w813": "n00b",
"5uck5": "sux0r"
},
wordsArr,
text;
function changeLetters() { // change all letters
text = elite.value.toLowerCase();
for (var i = 0; i < text.length; i++) {
if (alphabets[text[i]]) {
text = text.replace(text[i], alphabets[text[i]]);
}
}
// leet.value = text;
}
function changeWords() { // change special words
wordsArr = text.split(" ");
for (var i = 0; i < wordsArr.length; i++) {
if (words[wordsArr[i]]) {
wordsArr[i] = words[wordsArr[i]];
}
}
}
function tol33t() {
changeLetters();
changeWords();
leet.value = wordsArr.join(" ");
}
elite.addEventListener("input", tol33t);
document.getElementById("btn").addEventListener("click", tol33t);
你可以看到,我將它們轉換爲LEET後更換的話。但我正在琢磨如何直接替換單詞。我的意思是使用我評論的對象。 從「冷」到「kwel」不是從「c00l」到「KEWL」
***請查看更新的問題 - leet speak translator critical bug
你試圖完成什麼? 'changeLetters()'會將'cool'改爲'c00l',然後'changeWords()'將改變爲'kewl'。有什麼問題嗎? – JLRishe
我正在尋找一種方法來將單詞「cool」,「hacker」直接轉換爲「kewl」和「haxor」,然後將其他字母轉換爲'changelettrs()' – user3079292
@ user3079292:調用您的調用順序? –