对于下面的代码,它显然只会记录" m"在“" man"因为" 0"。如何记录所有三个字母?
var userChoice = prompt("let me encode something!");
var userChoice = (userChoice.charCodeAt(0) );
console.log (userChoice);
答案 0 :(得分:0)
使用普通循环(向后兼容旧版浏览器)循环遍历userChoice
中的所有字符var userChoice = prompt("let me encode something!");
for (var i = 0; i < userChoice.length; i++) {
console.log (userChoice.charCodeAt(i));
}
答案 1 :(得分:0)
怎么回事?
var userChoice = prompt("let me encode something!");
for (i = 0; i < userChoice.length; i++) {
console.log(userChoice.charAt(i));
}
var userChoice = prompt("let me encode something!");
for (i = 0; i < userChoice.length; i++) {
console.log(userChoice.charCodeAt(i));
}