var str='Rome was not built in a day'
str=str.replace(/ /g,"")
console.log(str)
var sum=0
for(var i of str){
sum++
}
console.log(sum)
//给大家一个任意的字符串,如何实现把字符串中的字符顺序颠倒。如给你"abcde",你要得到"edcba"。
var str='abcde'
var strlength=str.length
var arr=[]
for(var i=0;i<strlength;i++){
arr[i]=str.charAt(i);
}
for(var i=strlength-1;i>=0;i--){
document.write(arr[i]);
}
//利用3种循环来计算1+2+3+…+100的值。
//1 .for循环
var sum1 = 0;
for (var i = 0; i <= 100; i++) {
sum1 = sum1 + i;
}
document.write(sum1);
document.write("<br />");
//2. while()循环
var sum2 = 0;
var i = 0;
while (i <= 99) {
i++;
sum2 += i;
}
document.write(sum2);
document.write("<br />");
// do-while语句
var sum3 = 0;
var i = 0;
do {
i++;
sum3 += i;
}
while (i <= 99);
document.write(sum3);
console