function writeDocument(variable){
document.write(variable+"<br/>");
}
writeDocument("===============================");
/*如果有一个字符串"Rome was not built in a day"
请用程序统计该字符串中字符的个数
不允许使用字符串对象的length属性 */
var str="Rome was not built in a day"
writeDocument(str);
outSpace=str.replace(/\s+/g,"");
var n=0;
for(var i of outSpace){
n++;
}
writeDocument("共有"+n+"个单词");
writeDocument("===============================");
/*给大家一个任意的字符串,
如何实现把字符串中的字符顺序颠倒。
如给你"abcde",你要得到"edcba"。*/
function reverse(str){
var arr=[];
for(var i=str.length-1;i>=0;i--){
arr.push(str[i]);
}
return arr.join("");
}
writeDocument("字符串原本:"+'abcde');
writeDocument("字符串颠倒:"+reverse('abcde'));
writeDocument("===============================");
//利用3种循环来计算1+2+3+…+100的值
var sum=0;
var i=1;
while(i<=100){
sum+=i;
i++;
}
writeDocument("While~~~"+sum);
var sum=0;
for(var i=0;i<=100;i++){
sum+=i;
}
writeDocument("For~~~~"+sum);
var sum=0;
var i=1;
do{
sum=sum+i;
i++;
}
while(i<=100);
writeDocument("Do.while~"+sum);
console