// 1.如果有一个字符串"Rome was not built in a day",
//请用程序统计该字符串中字符的个数,不允许使用字符串对象的length属性。
a="Rome was not built in a day";
b =a.replace(/\s/g);//去掉所有的空格
var sum =0;
for(var i of a)
{
sum++;
}
document.write(sum);
document.write("<br />");
//2.给大家一个任意的字符串,如何实现把字符串中的字符顺序颠倒。如给你"abcde",你要得到"edcba"
c='abcde';
var arr =[];
for(var i=c.length-1;i>=0;i--)
{
arr.push(c[i]);
}
document.write(arr.join(""));
document.write("<br />");
//3.利用3种循环来计算1+2+3+…+100的值。
//3.1 while 循环
sum = 0;
i = 1;
while(i<= 100){
sum += i;//在储存数值的变量里面循环储存i的值
i++;//每循环一次,自增变量都+1
}
document.write(sum);
document.write("<br />");
//3.2 for 循环
sum2 = 0;
for(i2=1;i2<=100;i2++){
sum2 += i2;
}
document.write(sum2);
document.write("<br />");
//3.3 do while 循环
sum3 = 0;
i3 = 1;
do {
sum3 += i3;
i3++;
}while(i3<=100);
document.write(sum3);
document.write("<br />");
console