【发布时间】:2014-06-02 21:29:02
【问题描述】:
我在没有老师的情况下做练习题,所以我上网寻求帮助。
我正在尝试解决这个问题:
编写一个函数 translate() 将文本翻译成“rövarspråket”。也就是说,将每个辅音加倍,并在其间放置一个“o”。例如, translate("this is fun") 应该返回字符串 "tothohisos isos fofunon"。
但是,当我尝试区分元音和辅音时,我遇到了一个问题。这就是我所拥有的:
function translate(text){
var newText;
if (!(text.charAt(0) == "a" || "e" || "i" || "o" || "u")){
newText = text.charAt(0) + "o" + text.charAt(0);
} else {
newText = text.charAt(0);
}
for (var i = 0; i<text.length; i++){
if (!(text.charAt(i) == "a" || "e" || "i" || "o" || "u")){
newText += text.charAt(i) + "o" + text.charAt(i);
} else {
newText += text.charAt(i);
}
}
console.log(newText);
}
translate("hello this is");
谁能解释为什么 ||运营商不工作?我认为这将解决我遇到的问题。
【问题讨论】:
标签: javascript for-loop operator-keyword