2015-11-16 38 views
-1

快速的問題。我試圖用JavaScript中的for循環給出數字。 不幸的是,這是行不通的,如果我在java中編碼,那麼解決方案將用char和cosole.log替換var與println並得到它,但在這裏...你有解決方案嗎?for循環與字符java腳本

for (var i = 'a'; i < 'z'; i++) { 
    console.log(i); 
} 
+1

謝謝兄弟,我永遠也不會發現它:-) – Mchoeti

回答

-1

for (var i = 'a'; i !== 'z'; i = nextChar(i)) { 
 
     console.log(i); 
 
    } 
 
    
 
    function nextChar(c) { 
 
     return String.fromCharCode(c.charCodeAt(0) + 1); 
 
    }

爲(VAR I = 'A';!我== 'Z'; I = nextChar(ⅰ)){ 的console.log(ⅰ); }

function nextChar(c) { 
    return String.fromCharCode(c.charCodeAt(0) + 1); 
} 

http://jsfiddle.net/fLwf5ys1/

,或者如果你真的想要的字符的ASCII值:

http://jsfiddle.net/fLwf5ys1/1/

+0

我做了一個第一次犯錯,通過努力去做。 –

+0

謝謝你,一切順利 – Mchoeti

+0

@Mchoeti你不需要,但如果你真的喜歡它,我真的很喜歡upvote –